我正在尝试从浏览器将字符串作为文件发布,如this 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); }
});
我得到的错误是: Uncaught TypeError: req.part is not a function