使用 cURL 从 shell 发布 4GB 文件

2024-05-09

我尝试将文件大小为 4GB 的文件发布到 REST API。

cURL 不会上传此大小的文件,而是 POST 内容长度为 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

使用较小的文件将按预期工作。

-rw-r--r--  1 user1  wheel  4403200000  2 Jan 15:02 /work/large.png

为什么上传失败?那么,如何正确上传这样的文件呢?

Cheers.


我认为你应该考虑使用-T选项而不是--data-binary. The --data-binary将整个文件加载到内存中(curl 7.47)。最好的情况是速度很慢,最坏的情况是 OOM 杀手会回复Killed信息。

curl -XPOST -T big-file.iso https://example.com
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 cURL 从 shell 发布 4GB 文件 的相关文章

随机推荐