I'm currently experiencing a 403 error when attempting to use Azure's Node.js SDK. The function below works perfectly when I call it directly:
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)
}
})
}
However, when I call this from my wider application then I receive a 403 error:
{ 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' }
The problem is that I can't seem to debug this any further than a 403 error. As the code works perfectly independently then I know the access keys aren't a problem. Azure Storage allows you to log access data for Tables, Blobs and Queues, but not for File Service, which seems incredibly frustrating (https://learn.microsoft.com/en-us/rest/api/storageservices/fileservices/enabling-storage-logging-and-accessing-log-data#HowtoenableStorageLoggingusingtheWindowsAzureManagementPortal).
Has anyone got any ideas regarding how I could debug this further?
There was an issue in the ApplicationInsights package that causes 403 responses from storage. This issue was fixed in version 0.18.0.