2

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

Community
  • 1
  • 1
FriC
  • 786
  • 10
  • 14
  • SuperAgent runs on the server side. An alternative could be using jquery from a browser. See: http://api.jquery.com/jquery.post/ – leo.fcx Jul 16 '15 at 01:32
  • I have used superagent in the browser for ordinary get and posts. But I cannot figure out how to use it for this particular use-case. – FriC Jul 16 '15 at 01:34

1 Answers1

2

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.