How to use HTTP Client to upload an image to server

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By monkeyTester
:warning: Old Version Published before Godot 3 was released.

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?

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

namathos | 2020-06-17 17:34

:bust_in_silhouette: Reply From: guppy42

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