I am trying to post a string as a file from the browser, as described in this SO question
But I want to use superagent to do this. I tried the following:
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); }
});
The error I get is: Uncaught TypeError: req.part is not a function