我正在尝试从浏览器将字符串作为文件发布,如 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
最佳答案
在superagent项目中,有两个文件:./lib/client.js(在浏览器中使用),./lib/node/index.js(在node中使用)。 ./lib/client.js 中没有部分方法。
关于javascript - 如何在浏览器中使用 superagent 将字符串作为文件发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31443600/