如何在浏览器中使用 superagent 将 post 字符串作为文件

How to use superagent in browser to post a string as a file

我正在尝试 post 来自浏览器的字符串作为文件,如 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.

中没有部分方法