+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")

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()

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

in Engine by (14 points)

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.


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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.