使用Node.js从Box api v2中删除文件

时间:2022-04-17 16:02:31

Currently struggling to delete a file from Box in Node.js. I'm using the request module. The docs state that to delete a file, you must use the "delete" method. However, I'm getting a status 405 "method not allowed. I've already validated that req.body.id contains the correct information. Here's my code:

目前正在努力从Node.js中的Box中删除文件。我正在使用请求模块。文档声明要删除文件,必须使用“删除”方法。但是,我得到状态405“方法不允许。我已经验证了req.body.id包含正确的信息。这是我的代码:

    request({method:"DELETE",url:"https://upload.box.com/api/2.0/files/"+req.body.id.id,
      headers:{
        'Authorization': 'Bearer ' + req.session.box_access_token,
        'If-Match':req.body.id.etag
      }
    },function(err, response, body) {
      next();
    });

Any idea why I'm getting this error?

知道我为什么会收到这个错误吗?

1 个解决方案

#1


And I'm an idiot. Url should be: "https://api.box.com/2.0/files/". I had https://upload.box.com/api/2.0/files/".

我是个白痴。网址应为:“https://api.box.com/2.0/files/”。我有https://upload.box.com/api/2.0/files/“。

#1


And I'm an idiot. Url should be: "https://api.box.com/2.0/files/". I had https://upload.box.com/api/2.0/files/".

我是个白痴。网址应为:“https://api.box.com/2.0/files/”。我有https://upload.box.com/api/2.0/files/“。