+2 votes

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 resultcode 4 that means "RESULTCONNECTION_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

asked Jul 9 in Engine by ea4evb (14 points)

Hi,
do you have the project online somewhere?

Try this:
1. open the browser
2. hit F12 to open debugger
3. open the network tab
4. open the html5 project in the browser
5. look for the request
6. look in the console for any error messages

Maybe the browser blocks the request because of cross-origin-policy.
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

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!

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.