Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Beatrix |
im going to make a video app and i need the video link after update is this possible?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Beatrix |
im going to make a video app and i need the video link after update is this possible?
Reply From: | mingganglee |
already replied here
https://forum.godotengine.org/79098/httprequest-or-httpclient-for-upload-file-to-server
extends Node
func _ready():
var request = HTTPRequest.new()
request.connect("request_completed", self, "_request_callback")
add_child(request)
upload_file(request)
func _request_callback(result, response_code, headers, body) -> void:
if response_code == HTTPClient.RESPONSE_OK:
var response = str2var(body.get_string_from_utf8())
prints("response", response)
elif response_code == HTTPClient.STATUS_DISCONNECTED:
prints("not connected to server")
func upload_file(request: HTTPRequest) -> void:
var file_name = "icon.png"
var file = File.new()
file.open('res://%s' % file_name, File.READ)
var file_content = file.get_buffer(file.get_len())
var body = PoolByteArray()
body.append_array("\r\n--BodyBoundaryHere\r\n".to_utf8())
body.append_array(("Content-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n" % file_name).to_utf8())
body.append_array("Content-Type: image/png\r\n\r\n".to_utf8())
body.append_array(file_content)
body.append_array("\r\n--BodyBoundaryHere--\r\n".to_utf8())
var headers = [
"Content-Type: multipart/form-data; boundary=BodyBoundaryHere"
]
var error = request.request_raw("http://localhost:5000", headers, true, HTTPClient.METHOD_POST, body)
if error != OK:
push_error("An error occurred in the HTTP request.")
pass