使用curl上传图片

时间:2016-04-02 06:17:18

标签: linux image bash curl upload

我想使用curl cli版本将图像上传到远程站点,我在这里浏览了几个页面,但无法解决我的问题。 我在上传图片时在Firefox中记录http标头:

https://www.site.xxx/upload_profile_picture/

POST /upload_profile_picture/ HTTP/1.1
Host: www.site.xxx
User-Agent: Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
Accept: */*
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Content-Type: multipart/form-data; boundary=---------------------------124439777612656977621176581961
Cookie: 123
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache


BELOW IS POSTDATA:::
-----------------------------124439777612656977621176581961
Content-Disposition: form-data; name="profile_pic"; filename="7eddaf78bbd055460167bae9eee3cdea.jpg"
Content-Type: image/jpeg

ÿØÿà

2 个答案:

答案 0 :(得分:1)

基本curl语法为

curl \ -F "image=@/yourPath/yourImageFile.jpg" \ 'https://www.site.xxx/upload_profile_picture/'

如有必要,请指定包含一个或多个其他-F选项的其他POST数据字段,如-F "username=xxx"

答案 1 :(得分:0)

或者您可以使用Chrome,它会在检查器中为您构建cURL命令: enter image description here