首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure函数在尝试写入本地文件系统时超时或出错

Azure函数在尝试写入本地文件系统时超时或出错
EN

Stack Overflow用户
提问于 2017-07-12 18:19:36
回答 1查看 425关注 0票数 0

我想要做的是:逻辑应用程序将excel文件从SFTP保存到blob存储。然后,逻辑应用程序将blob详细信息传递给azure函数,该函数检索blob并在本地存储。Next函数为本地存储的excel文件提供路径,并将其解析为JSON。然后将该JSON插入到DB中。我让这些都在本地工作。

问题是如何获得第一个函数,在其中传递blob的fileName和容器并读取它。从那里它应该能拯救它。我尝试过在azure函数或'D:/local/Temp/上使用D:/HOME,但没有成功。

我要么在使用这些路径时得到这个异常

代码语言:javascript
复制
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详细信息的功能

代码语言:javascript
复制
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存储器读取并保存文件

代码语言:javascript
复制
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存储,这很奇怪,因为请求与我的本地请求完全相同。

EN

回答 1

Stack Overflow用户

发布于 2017-07-12 19:04:12

...and,我想出来了

显然,我在函数应用程序中的AzureWebJobsStorage值指向了一个不同的存储空间。用正确的方法更新它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45064964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档