Hi everyone,
I’m looking to upload files via an API using Julia with the HTTP.jl package. Unfortunately, the API can’t retrieve my file, and I get an error:
{“code”:500,“message”:“Unable to retrieve file from request.”,“payload”:}
Here is my code (the API key is a public one for the public test API, anyone can try ;))
using HTTP
url = "https://apitest.nakala.fr/datas/uploads"
headers =
Dict(
"X-API-KEY" => "01234567-89ab-cdef-0123-456789abcdef",
"accept" => "application/json"
)
fileOpened = open(PATH_TO_THE_FILE, "r")
fileCur = Dict("file" => fileOpened)
response = HTTP.post(url, files=fileCur, headers=headers)
I wrote a similar script with Python and everything seems to work:
import requests
url = "https://apitest.nakala.fr/datas/uploads"
headers = {"X-API-KEY":"01234567-89ab-cdef-0123-456789abcdef", "accept": "application/json"}
fileOpened = open(PATH_TO_THE_FILE, "rb")
fileCur = {'file': fileOpened}
response = requests.post(url, files=fileCur, headers=headers)
print(str(response.text))
The (good) response from the server:
{“name”:“myFile.txt”,“sha1”:“35b7740a641464a2dfecd282ba0592a8a23f65a3”}
I must have made a mistake with objects sent with HTTP.post but I don’t know how to fix it… Does anyone have any ideas?
Thanks a lot!!
Josselin