【发布时间】:2014-01-24 12:39:30
【问题描述】:
如何使用来自 Nodejs 的 MultiPart 使用请求发送文件?
这将与Curl的以下命令相同:
curl -X POST -F "photos[]=@img.jpg;type=image/jpg" https://example.com
它创建的 Http 请求:
{
"json": null,
"files": {
"photos[]": "data:image/jpg;base64,[Binary]
},
"form": {},
"headers": {
"Accept": "*/*",
"Content-Type": "multipart/form-data; boundary=----------------------------0195fbe0d4ab",
"Connection": "close",
"Host": "httpbin.org",
"Content-Length": "42311",
"User-Agent": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5"
},
"origin": "23.125.128.191",
"data": "",
"url": "http://httpbin.org/post",
"args": {}
}
【问题讨论】:
-
对“nodejs 多部分表单数据”的简单搜索揭示了这一点:github.com/felixge/node-form-data。请记住:Node.js 已经有大量可用的操作系统模块,只需搜索一下!
-
@SimonPlus 您可能应该提交该评论作为答案,并提及自述文件中的一个示例