Httpie: Can't send POST request with multiple files

Created on 20 Oct 2014  路  10Comments  路  Source: httpie/httpie

I'm trying this:

http -f POST http://localhost:8000/products/images files\[\]@B497A_1.jpg files\[\]@B497A_2.jpg

But the request only contains the last file.

Do we have support for multiple files yet?

Most helpful comment

@wordyallen

http -f :3090/api/lots  [email protected]  [email protected]

(Please create a new issue if you are still having an issue with the syntax.)

All 10 comments

Can you provide more details? There should be no problem uploading multiple files.

Iit works for me:

$ echo a > a.txt
$ echo b > b.txt
$ http -vf httpbin.org/post [email protected] [email protected]
POST /post HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Content-Length: 242
Content-Type: multipart/form-data; boundary=38516d25820c4a9aad05f1e42cb442f4
Host: httpbin.org
User-Agent: HTTPie/0.8.0

--38516d25820c4a9aad05f1e42cb442f4
Content-Disposition: form-data; name="a"; filename="a.txt"

a

--38516d25820c4a9aad05f1e42cb442f4
Content-Disposition: form-data; name="b"; filename="b.txt"

b

--38516d25820c4a9aad05f1e42cb442f4--
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 532
Content-Type: application/json
Date: Mon, 20 Oct 2014 10:36:23 GMT
Server: gunicorn/18.0

{
    "args": {},
    "data": "",
    "files": {
        "a": "a\n",
        "b": "b\n"
    },
    "form": {},
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Connection": "close",
        "Content-Length": "242",
        "Content-Type": "multipart/form-data; boundary=38516d25820c4a9aad05f1e42cb442f4",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/0.8.0",
        "X-Request-Id": "2ff6f64c-8074-4636-9fb1-9178b6d6210e"
    },
    "json": null,
    "url": "http://httpbin.org/post"
}

I mean multiple files on a single array. With curl, I do it like this:

curl -i -F files\[\]=@B497A_1.jpg -F files\[\]=@B497A_2.jpg http://localhost:8000/products/images

I see now. It looks like there is a bug regarding multiple files (or form fields) with the same name.

Thanks for the quick response, @jakubroztocil.

I will be happy to help fixing it.

Can you point me in the right direction?

Thanks @drgomesp, I'm actually looking into this now.

(The main place where changes need to be made: https://github.com/jakubroztocil/httpie/blob/master/httpie/input.py#L583)

Hello,

I couldn't find the syntax for this in the docs.

http -f post localhost:3090/api/lots photos@[/]200.png photos@[/]300.png

this didn't work.

Thanks,
Joe

@wordyallen

http -f :3090/api/lots  [email protected]  [email protected]

(Please create a new issue if you are still having an issue with the syntax.)

wow. thanks!

Is this working for you ?

For me this syntax is working :

http -f :3090/api/lots photos[]@200.png photos[]@300.png

Is this still working for anybody? I can't get it to work with any of the above syntax. Running in the HTTPie demo:

$ echo a > a.txt
$ echo b > b.txt
$ http -f httpbin.org/post [email protected] [email protected]
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 360
Content-Type: application/json
Date: Thu, 13 Jun 2019 16:22:56 GMT
Server: gunicorn/19.9.0

{
    "args": {},
    "data": "",
    "files": {
        "files": "a\n"
    },
    "form": {},
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Connection": "keep-alive",
        "Content-Length": "302",
        "Content-Type": "multipart/form-data; boundary=44226e711ad05c462d7c07d70d67c925",
        "Host": "httpbin.org",
        "User-Agent": "HTTPie/1.0.0"
    },
    "json": null,
    "origin": "127.0.0.1",
    "url": "http://httpbin.org/post"
}

$
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cunde picture cunde  路  7Comments

loretoparisi picture loretoparisi  路  6Comments

hrj picture hrj  路  5Comments

rshurts picture rshurts  路  5Comments

a-x- picture a-x-  路  7Comments