简体   繁体   中英

Azure Function timing out or erroring when trying to write to local filesystem

What I am trying to accomplish: logic app saves excel file from SFTP to blob storage. Logic app then passes blob details to azure function that retrieves blob and stores locally. Next function takes the path for that locally stored excel file and parses it to JSON. That JSON is then inserted in the DB. I have this all working locally.

The problem is trying to get the first function where you pass it the fileName and container of the blob and read it. From there it should save it. I have tried using D:/HOME on the azure function or 'D:/local/Temp/ with no success.

I either get this exception when using those paths

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).

Here is my function to receive the blob details

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"
    });
}
};

Here is my repo to read from blob storage and save the file

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;

Any ideas?

edit : It seems after further research that a blank file is created on the D:\\Home directory but contains nothing. The error seems to be pointed to blob storage which is weird because the request is the exact same as my local one.

...and I figured it out

Apparently my AzureWebJobsStorage value in function app was pointed to a different storage. Updating that with the correct one fixed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM