0
var BlobSerivceClient = require('@azure/storage-blob');
var multipart = require('parse-multipart');
const AZURE_STORAGE_CONNECTION_STRING = process.env["connectionstringstoragepath"]

module.exports = async function (context, req) {
    context.log('Javascript HTTP trigger function processed a request '+multipart+" "+AZURE_STORAGE_CONNECTION_STRING+" "+blobSerivceClienttop);
    var bodyBuffer = Buffer.from(req.body);
    var boundary = multipart.getBoundary(req.headers['content-type']);

    var parts = multipart.Parse(bodyBuffer, boundary);
    const blobSerivceClient = await BlobSerivceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);

    const container = "bankfeedsdbfiles";
    const containerClient = await blobSerivceClient.getContainerClient(container);
    
    const blobName = parts[0].filename;

    const blockBlobClient = containerClient.getBlockBlobClient(blobName);
    const uploadblobResponse = await blockBlobClient.upload(parts[0].data, parts[0].data.length);

    context.res = {body: {name: parts[0].filename, type: parts[0].type, data: parts[0].data.length}};
    context.done();
} 

以上是我的代码,我收到如下错误:

2021-12-27T09:49:25.507 [错误] 执行“Functions.dbfilesupload”(失败,ID = fa953980-82b2-4c95-a13e-13988fd1c67e,持续时间 = 240 毫秒)结果:FailureException:TypeError:blobSerivceClienttop.fromConnectionString 不是函数堆栈: TypeError: blobSerivceClienttop.fromConnectionString is not a functionat module.exports (D:\home\site\wwwroot\dbfilesupload\index.js:13:58) at t.WorkerChannel.invocationRequest (D:\Program Files (x86)\SiteExtensions \Functions\4.0.1\workers\node\worker-bundle.js:2:16866) 在 c。(D:\Program Files (x86)\SiteExtensions\Functions\4.0.1\workers\node\worker-bundle.js:2:13767) 在 c.emit (events.js:400:28) 在 addChunk (internal/在 Object.onReceiveMessage (D :\Program Files (x86)\SiteExtensions\Functions\4.0.1\workers\node\worker-bundle.js:2:66126) 在 Object.onReceiveMessage (D:\Program Files (x86)\SiteExtensions\Functions\4.0.1 \workers\node\worker-bundle.js:2:58414) 位于 D:\Program Files (x86)\SiteExtensions\Functions\4.0.1\workers\node\worker-bundle.js:2:32555。我还为@azure/storage-blob 和 parse-multipart 安装了包

4

1 回答 1

0

我尝试读取本地系统的多个文件以进行测试,您可以尝试传递数据并尝试blobSerivceClienttop在代码中删除

const { BlobServiceClient } = require('@azure/storage-blob');


const blobServiceClient = BlobServiceClient.fromConnectionString("Connection string");

// Create a unique name for the container


console.log('\nCreating container...');


var fs = require('fs');
async = require('async');
  
var dirPath = local file path'; //provice here your path to dir

fs.readdir(dirPath, function (err, filesPath) {
    if (err) throw err;
    filesPath = filesPath.map(function(filePath){ //generating paths to file
        console.log(dirPath+filePath);
       
       
        return dirPath + filePath;
        
    });
    async.map(filesPath, function(filePath, cb){ //reading files or dir
        fs.readFile(filePath, 'utf8', cb);
    }, function(err, results) {
        for (var i = 0; i < results.length; i++){
            const containerClient = blobServiceClient.getContainerClient("test");
            const blockBlobClient = containerClient.getBlockBlobClient(filesPath[i]);
            blockBlobClient.upload(results[i],results[i].length);
            console.log("HIIIIIIIIIIIIIIIiiiiii")
        console.log(results[i]);
        } //this is state when all files are completely read
       
    });
});

在此处输入图像描述

于 2021-12-28T12:29:46.367 回答