我目前在尝试使用 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#Howtoenable Storage Logging using the WindowsAzureManagementPortal)。
有没有人对我如何进一步调试有任何想法?