+1 vote

How would you upload an image to a server using HttpClient. What i have so far is below.

var r=RawArray()
r.append("----WebKitFormBoundaryePkpFF7tjBAqx29L\n")
r.append("Content-Disposition: form-data; name=\"imgFile\"; filename=\"cube.png\"\n")
r.append("Content-Type: image/png\n")
r.append("\n")
var file = File.new()
file.open("res://Template/cube.png", file.READ)
var content = file.get_buffer(file.get_len())
file.close()
r.append_array(content)
r.append("----WebKitFormBoundaryePkpFF7tjBAqx29L")
var headers=[
   "Content-Length: "+String(content.size()),
   "Content-Type: multipart/form-data,  boundary=----WebKitFormBoundaryePkpFF7tjBAqx29L"
]
err=http.request_raw(HTTPClient.METHOD_POST,"/BloxPhp/MeshUpload.php",headers,r)

However this returns am empty array when print $POST. Is my approach correct?

in Engine by (18 points)

Did you ever solve this? I'm looking into something similar and no luck yet.

1 Answer

+1 vote

Assuming the server is PHP you need to the check $_FILES array

by (366 points)
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 webmaster@godotengine.org with your username.