无法使用节点将文件上传到Box

Unable to upload file to Box using Node

我很难使用 Node.js.

将我的文件上传到盒子

每次尝试时,我都会收到以下错误:

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

这是相关代码。我已经仔细检查过 this.options.auth 是否包含所需的标记等。parent_id 文件夹是根文件夹,因此为“0”。文件路径是一个流,完全没问题。

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);
});

有什么想法吗?

HTTP 状态代码 400 用于错误请求。要检查的一件事是您提供的参数都是有效的,并且您没有忘记任何必需的参数。查看 the Box API getting-started doc,看来您调用的 parent_id 应该只是 parent。如果还是不行,当然还要检查其他类似问题。