Send file with

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 = ""

headers = 
        "X-API-KEY" => "01234567-89ab-cdef-0123-456789abcdef", 
        "accept" => "application/json"

fileOpened = open(PATH_TO_THE_FILE, "r")    

fileCur = Dict("file" => fileOpened)

response =, files=fileCur, headers=headers)

I wrote a similar script with Python and everything seems to work:

import requests

url = ""

headers = {"X-API-KEY":"01234567-89ab-cdef-0123-456789abcdef", "accept": "application/json"}

fileOpened = open(PATH_TO_THE_FILE, "rb")    

fileCur = {'file': fileOpened}

response =, files=fileCur, headers=headers)


The (good) response from the server:


I must have made a mistake with objects sent with but I don’t know how to fix it… Does anyone have any ideas?

Thanks a lot!!

HTTP.jl’s API is different from Python’s requests. In particular, HTTP.request (post is a convenience method for request), doesn’t know the keyword arguments files and headers.

Instead it is called as, headers, body).

I believe something like

body = HTTP.Form(Dict(:file => fileOpened))

would do the trick. See API Reference · HTTP.jl

Your headers seem fine, but maybe you need to declare

Content-Type => multipart/form-data

No guarantees though, I’m not an expert.

@skleinbo thank you very much for your help, it works perfectly!!

That’s great! If you are happy with my answer, and feel like your problem is fully resolved, please mark it as the solution.

1 Like