我想要完成的任务:逻辑应用程序将excel文件从SFTP保存到blob存储。逻辑应用程序然后将blob详细信息传递给azure函数,该函数检索blob并在本地存储。 Next函数获取本地存储的excel文件的路径并将其解析为JSON。然后将JSON插入数据库中。我把这一切都在当地工作。
问题是尝试获取第一个函数,在其中传递blob的fileName和容器并读取它。从那里它应该保存它。我尝试在azure函数上使用 D:/ HOME 或'D:/ local / Temp / 但没有成功。
我在使用这些路径时遇到此异常
Exception while executing function: Functions.retrieveAndStoreBlobFile. mscorlib: StorageError: NotFound
at Function.StorageServiceClient._normalizeError (D:\home\site\wwwroot\node_modules\azure-storage\lib\common\services\storageserviceclient.js:1181:23)
at BlobService.StorageServiceClient._processResponse (D:\home\site\wwwroot\node_modules\azure-storage\lib\common\services\storageserviceclient.js:736:50)
at Request.processResponseCallback [as _callback] (D:\home\site\wwwroot\node_modules\azure-storage\lib\common\services\storageserviceclient.js:317:37)
at Request.self.callback (D:\home\site\wwwroot\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> (D:\home\site\wwwroot\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> (D:\home\site\wwwroot\node_modules\azure-storage\node_modules\request\request.js:965:12).
这是我接收blob详细信息的功能
var blobRepo = require("../repository/blobStorage.js");
const localFileStoragePath = process.env["LocalDiskLocation"];
module.exports = function (context, req) {
context.log('Blob HTTP trigger function processed a request.');
context.log('Local path: ' + localFileStoragePath);
if(req.body){
var fileName = req.body.fileName;
var container = req.body.container;
blobRepo.getBlob(container, fileName).then( (result) => {
// Return blob details
context.done(null, {
status: 200,
body: {
"blobDetails" : result.blobDetails,
"filePath" : result.filePath
}
})
}).catch( (err) => {
context.done(err);
});
}
else {
context.done("Please pass a name on the query string or in the request body", {
status: 400,
body: "Please pass a name on the query string or in the request body"
});
}
};
这是我从blob存储中读取的repo并保存文件
var azure = require('azure-storage');
var fs = require('fs');
const localFileStoragePath = process.env["LocalDiskLocation"];
var webStorageConnectionString = process.env["AzureWebJobsStorage"];
var blobService = azure.createBlobService(webStorageConnectionString);
var exportObject = {
getBlob: function(container, blobName){
return new Promise ( (resolve, reject) => {
// Read file from blob and store on drive
blobService.getBlobToStream(container, blobName,
fs.createWriteStream(localFileStoragePath + blobName), function(error, serverBlob) {
if(error){
reject(error);
return;
}
const blobDetails = {
filePath: localFileStoragePath + blobName,
blobDetails: JSON.stringify(serverBlob)
}
// Return blob details and path to file
resolve(blobDetails);
});
});
}
}
module.exports = exportObject;
有什么想法吗?
编辑:经过进一步研究后,似乎在D:\ Home目录中创建了一个空白文件,但什么都没有。该错误似乎指向blob存储,这很奇怪,因为请求与我的本地请求完全相同。
答案 0 :(得分:0)
......我想通了
显然,我在功能应用中的AzureWebJobsStorage值指向了不同的存储空间。用正确的修正它来更新它。