Unable to upload file to Box using Node

I'm having a really tough time getting my files to upload to box using Node.js.

Every single time I attempt to, I get the following error:

Error: cannot POST /api/2.0/files/content (400)

Here is the relevant code. I've already double checked that this.options.auth contains the required tokens, etc. The parent_id folder is the root folder, so '0'. The filepath is a stream, which is totally fine.

request.post('https://upload.box.com/api/2.0/files/content')
.set('Authorization', this.options.auth)
.field('parent_id', folder)
.attach('filename', filepath)
.end(function (res) {
  if (res.error) {
    return callback('Error: '+res.error.message);
  }
  callback(null, res.body);
});

Any ideas?

Answers


HTTP status code 400 is used for a bad request. One thing to check is that the parameters you are supplying are all valid and that you haven't forgotten any required parameters. Looking at the Box API getting-started doc, it appears that what you are calling parent_id should be just parent. If it still doesn't work, check for other similar issues too, of course.


Need Your Help

Accordion style tableview without using sections

iphone ios objective-c uitableview cells

I am interning for the summer on an iOS native app development team. They gave me a task of accomplishing removing/inserting cells in a tableview without using sections. I am struggling with the ta...

how to send sms via a dual sim mobile using serial port

c# modem at-command

I am sending sms to recipients using following code

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.