austin809
austin809

Reputation: 359

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?

Upvotes: 0

Views: 649

Answers (1)

Trott
Trott

Reputation: 70133

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.

Upvotes: 1

Related Questions