I try to post a file with a filesize of 4GB to a REST API.
Instead of uploading a file with this size, cURL POSTs a file with Content-Length: 0.
curl -v -i -d @"/work/large.png" -H "Transfer-Encoding: chunked" http://localhost:8080/files
* Adding handle: conn: 0x7fcafc00aa00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fcafc00aa00) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
* Trying localhost...
* Connected to localhost (localhost) port 8080 (#0)
> POST /files HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8080
> Accept: */*
> Transfer-Encoding: chunked
> Authorization: bearer XXX.XXX.XXX
> x-user-token: bearer XXX.XXX.XXX
* upload completely sent off: 5 out of 0 bytes
< HTTP/1.1 201 Created
HTTP/1.1 201 Created
< Date: Thu, 02 Jan 2014 14:55:46 GMT
Date: Thu, 02 Jan 2014 14:55:46 GMT
< ETag: "d41d8cd98f00b204e9800998ecf8427e"
ETag: "d41d8cd98f00b204e9800998ecf8427e"
< Location: http://localhost:8080/files/66032e34-9490-4556-8495-fb485ca12811
Location: http://localhost:8080/files/66032e34-9490-4556-8495-fb485ca12811
* Server nginx/1.4.1 is not blacklisted
< Server: nginx/1.4.1
Server: nginx/1.4.1
< Content-Length: 0
Content-Length: 0
< Connection: keep-alive
Connection: keep-alive
Using files with a smaller size will work as expected.
-rw-r--r-- 1 user1 wheel 4403200000 2 Jan 15:02 /work/large.png
Why does the upload fail? And, how to correctly upload such a file?
Cheers.
To post a file with Curl, use the -d or -F command-line options and start the data with the @ symbol followed by the file name. To send multiple files, repeat the -F option several times.
Send the data using curl's –d or –data option. To execute a CURL file upload, you need to use the –d command-line option and begin data with the @ symbol. The file's name should come after the data with @ symbol so CURL can read it and send it to the server.
With curl, you add each separate multipart with one -F (or --form ) flag and you then continue and add one -F for every input field in the form that you want to send. The above small example form has two parts, one named 'person' that is a plain text field and one named 'secret' that is a file.
To upload to an FTP server, you specify the entire target file path and name in the URL, and you specify the local file name to upload with -T, --upload-file . Optionally, you end the target URL with a slash and then the file component from the local path will be appended by curl and used as the remote file name.
I think you should consider using -T
option instead of --data-binary
. The --data-binary
loads the entire file into memory (curl 7.47). At best it is slow, at worst the OOM killer will reply with a Killed
message.
curl -XPOST -T big-file.iso https://example.com
To upload large binary files using CURL you'll need to use --data-binary
flag.
In my case it was:
curl -X PUT --data-binary @big-file.iso https://example.com
Note: this is really an extended version of @KarlC comment, which actually is the proper answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With