Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ea4evb |
Hi everyone!
I’m newie in Godot and I’m stuck with this.
I have a scene that loads an image from a web server via HttpRequest. The image is loaded into a new texture and assigned to a TextureButton.
Here is the code:
func _ready():
$HTTPRequest.connect("request_completed", self, "_http_request_image_completed")
$HTTPRequest.request("https://via.placeholder.com/150")
func _http_request_image_completed (result, response_code, headers, body):
var image = Image.new()
var image_error = image.load_png_from_buffer(body)
if image_error != OK:
print ("Can't show the image")
var texture = ImageTexture.new()
texture.create_from_image(image)
$TextureButton.texture_normal=texture
Everything works fine when it runs on the debugger or even when is exported to android, but when I try to export the project to HTML5 I’ve got a result_code 4 that means “RESULT_CONNECTION_ERROR = 4. Request failed due to connection (read/write) error.”
I have tried accessing images that are served in both https and http with the same result when the project is exported to HTML5.
I would appreciate any help.
Many thanks in advance.
Godot 3.2.1
Hi,
do you have the project online somewhere?
Try this:
- open the browser
- hit F12 to open debugger
- open the network tab
- open the html5 project in the browser
- look for the request
- look in the console for any error messages
Maybe the browser blocks the request because of cross-origin-policy.
Same-origin policy - Security on the web | MDN
klaas | 2020-07-09 16:42
Hi,
That’s it. I’ve uploaded the image in a localserver that has the header Access-Control-Allow-Origin: *. Now the image is shown in the scene.
Many thanks!
ea4evb | 2020-07-10 08:19