Node.js Azure文件服务 - 403错误调试

时间:2017-04-05 21:26:00

标签: node.js azure azure-storage-files

我在尝试使用Azure的Node.js SDK时遇到403错误。当我直接调用它时,下面的功能非常有效:

module.exports = function (file, callback) {
  if (!fs.existsSync('./data')) {
    mkdirp('./data', function (err) {
      if (err) console.log(err)
    })
  }
  fileService.getFileToStream('chatbot', '', file, fs.createWriteStream('data/' + file), function (err, res, response) {
    if (!err) {
      fs.readFile('data/' + file, 'utf8', function (err, data) {
        if (!err) {
          callback(null, data)
        } else {
          callback(err)
        }
      })
    } else {
      callback(err)
    }
  })
}

但是,当我从更广泛的应用程序中调用它时,我收到403错误:

{ StorageError: Forbidden
    at Function.StorageServiceClient._normalizeError (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/lib/common/services/storageserviceclient.js:1174:23)
    at FileService.StorageServiceClient._processResponse (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/lib/common/services/storageserviceclient.js:729:50)
    at Request.processResponseCallback [as _callback] (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/lib/common/services/storageserviceclient.js:310:37)
    at Request.self.callback (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/node_modules/request/request.js:187:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/node_modules/request/request.js:1044:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (/Users/tombarton/Sites/TestApplication/node_modules/azure-storage/node_modules/request/request.js:965:12)
  name: 'StorageError',
  message: 'Forbidden',
  code: 'Forbidden',
  statusCode: 403,
  requestId: '51ce6605-001a-00c1-1d52-ae966b000000' }

问题在于我似乎无法进行调试,而不是403错误。由于代码完全独立工作,我知道访问密钥不是问题。 Azure存储允许您记录表,Blob和队列的访问数据,但不能记录文件服务的访问数据,这似乎非常令人沮丧(https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/enabling-storage-logging-and-accessing-log-data#HowtoenableStorageLoggingusingtheWindowsAzureManagementPortal)。

有没有人对我如何进一步调试有任何想法?

2 个答案:

答案 0 :(得分:2)

您可以在其间放置调试代理,例如mitmproxyFiddlerCharles,以查看请求和响应之间的区别。

NODE_TLS_REJECT_UNAUTHORIZED=0 HTTP_PROXY=http://127.0.0.1:8888 node app.js

答案 1 :(得分:1)

issue in the ApplicationInsights package导致存储的403响应。此问题已在0.18.0版中修复。