【问题标题】:Curl POST Form with Image File to Form将带有图像文件的 POST 表单卷曲到表单
【发布时间】:2023-03-18 11:15:02
【问题描述】:

我正在尝试将 JPEG 图像从特定文件目录发布到服务器 curl。这是我输入的:

curl -v -include --form filedata='/home/pi/Documents/2014-01-18-09:11:25.jpeg' http://hostdomain.me/file/upload

执行此命令后,终端返回以下内容:

* Couldn't find host rdnvpfwnwk.localtunnel.me in the .netrc file; using defaults
* About to connect() to rdnvpfwnwk.localtunnel.me port 80 (#0)
*   Trying 192.34.58.73...
* connected
* Connected to rdnvpfwnwk.localtunnel.me (192.34.58.73) port 80 (#0)
> POST /file/upload HTTP/1.1
> User-Agent: curl/7.26.0
> Host: rdnvpfwnwk.localtunnel.me
> Accept: */*
> Content-Length: 186
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------affc91df7bc3
>
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue

* additional stuff not fine transfer.c:1037: 0 0
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 500 Internal Server Error
HTTP/1.1 500 Internal Server Error
< Server: nginx
Server: nginx
< Date: Sat, 18 Jan 2014 11:44:39 GMT
Date: Sat, 18 Jan 2014 11:44:39 GMT
< Content-Type: text/plain
Content-Type: text/plain
< Content-Length: 9245
Content-Length: 9245
< Connection: keep-alive
Connection: keep-alive
< X-Powered-By: Sails <sailsjs.org>
X-Powered-By: Sails <sailsjs.org>
* Added cookie sails.sid="s%3AAucWnGhDSzZSGB_tBgSXJoU2.DMQ4FuVVRRGLFGheMgr4CvIFUICCiP9Gqd5GIjRevA8" for domain rdnvpfwnwk.localtunnel.me, path /, expire 0
< Set-Cookie: sails.sid=s%3AAucWnGhDSzZSGB_tBgSXJoU2.DMQ4FuVVRRGLFGheMgr4CvIFUICCiP9Gqd5GIjRevA8; Path=/; HttpOnly
Set-Cookie: sails.sid=s%3AAucWnGhDSzZSGB_tBgSXJoU2.DMQ4FuVVRRGLFGheMgr4CvIFUICCiP9Gqd5GIjRevA8; Path=/; HttpOnly

* HTTP error before end of send, stop sending
<
TypeError: Cannot read property 'name' of undefined

在网站上使用表单时,它会正确发送。这是表格:

<form id="uploadForm"
enctype="multipart/form-data"
action="/file/upload"
method="post">
<input type="file" id="userPhotoInput" name="userPhoto" />
<input type="submit" value="Submit">
</form>

如何解决这个问题?

【问题讨论】:

    标签: node.js bash curl terminal sails.js


    【解决方案1】:

    使用这个:

    curl -v -include --form "userPhoto=@/home/pi/Documents/2014-01-18-09:11:25.jpeg" http://hostdomain.me/file/upload
                             ^^^^^^^^^ ^
    

    【讨论】:

    • 我无法解析 HTTP 正文 :: { [Error: Request aborted] status:4 400 } 在服务器上和 504 网关超时以响应终端中的 curl。有什么想法吗?
    • 可以在firefox上安装firebug;然后转到网络选项卡并将文件上传到您的站点;你可以看到你的请求;右键单击请求并选择 copy as cURL ;在此之后,如果您看到成功的上传文件,您可以将 curl 粘贴到 bash 上并运行它..
    猜你喜欢
    • 1970-01-01
    • 2017-07-14
    • 2012-09-06
    • 2018-10-21
    • 1970-01-01
    • 2019-02-25
    • 2020-01-25
    • 2013-10-25
    • 1970-01-01
    相关资源
    最近更新 更多