我正在尝试将字符串作为文件从浏览器发布,如SO question
中所述但我想用superagent来做这件事。我尝试了以下方法:
var request = require('superagent');
var boundary = "---------------------------7da24f2e50046";
var req = request.post('/api/items');
req.part()
.set('Content-Type', 'multipart/form-data; boundary='+boundary)
.set('Content-Disposition', 'form-data; name="file"')
.write('my-string')
;
req.end(function(err, response) {
if(err) { console.err(err.status_code); }
else { console.log(response.body); }
});
我得到的错误是:未捕获的TypeError:req.part不是函数
答案 0 :(得分:1)
In superagent project, there are two files: ./lib/client.js(using in browser), ./lib/node/index.js(using in node). no part method in ./lib/client.js.