Hello,
Is there a way to load a sprite image from a URL?
So trying to load dynamically from a list of URLs I get from an API call.
Thanks
Load a sprite from URL
Re: Load a sprite from URL
You will not be able to load an image from another website.
Your Browser will block it for security reasons.
Images must exist on the same server/location as your app.
Maybe read this thread for better explanation...
viewtopic.php?t=2265
Your Browser will block it for security reasons.
Images must exist on the same server/location as your app.
Maybe read this thread for better explanation...
viewtopic.php?t=2265
-
- Posts: 27
- Joined: Tue Nov 22, 2022 4:36 am
Re: Load a sprite from URL
Hello, so I'm looking at getting from HTTP the image itself. Since I got the response, can I pass it / encode / decode it into a format which I can LoadSprite into? Or worse case I guess I can put a script at the source URL (server) to convert the image into base64 and then I can read it into LoadSprite. However, I'd like to have it all in Spider and not have to maintain another script somewhere. There was a Base64Encoder function in PB but not in SB...
Code: Select all
Procedure HttpGetEvent(Success, Result$, UserData)
If Success
Debug Result$
Else
Debug "HTTPRequest(): Error"
EndIf
EndProcedure
; Get the content of this file, and display it in the debug window
;
HTTPRequest(#PB_HTTP_Get, "https://xxx.ngrok.io/static/test.jpg", "", @HttpGetEvent())
-
- Posts: 27
- Joined: Tue Nov 22, 2022 4:36 am
Re: Load a sprite from URL
I'm posting this so next time we're all good.
If you have control over your http server (in this case I have), with an Apache for example. You add it in your config or the .htaccess file. Look at the security risks before doing this. I don't have an issue because it's public images anyways.
This will allow your app to just do this directly.
Or you have to have an in-between proxy of some sort which will allow * origin and then get the file for you. Squid proxy or Nginx would do.
If you have control over your http server (in this case I have), with an Apache for example. You add it in your config or the .htaccess file. Look at the security risks before doing this. I don't have an issue because it's public images anyways.
Code: Select all
<VirtualHost *:443>
...
Header add Access-Control-Allow-Origin "*"
...
</VirtualHost>
Code: Select all
LoadSprite(0, "https://xxx.xxx-xx.com/xx/xx-xxx.jpg")