【问题标题】:Azure function ( blob trigger ) read CSV file with NodejsAzure 函数(blob 触发器)使用 Nodejs 读取 CSV 文件
【发布时间】:2021-12-26 17:14:26
【问题描述】:

使用 Nodejs 读取 azure 函数中的 myBlob 缓冲区参数并将其写入表存储的最佳方法是什么,因为我正在尝试使用大小为 16MB 的文件并且它太慢了。

另一件事是当我使用 context.log() 查看文件的内容时,它不会显示文件的所有内容,而只是显示其中的一部分。

module.exports = async function (context, myBlob) {

     let data = myBlob.toString("utf8");

     context.log("context", data);
};

【问题讨论】:

    标签: node.js azure csv azure-functions


    【解决方案1】:

    你可以在 nodejs 中使用 getBlobToStream 或 getBlobToText 来获取 blob 数据。 下面是读取 blob 所需的 function.json:

    {
      "bindings": [
        {
          "name": "Blob",
          "type": "blobTrigger",
          "dataType": "binary",
          "direction": "in",
          "path": "folderpath",
          "connection": "CONN_STR"
        }
      ]
    }
    

    与您提供的代码相关,我对其进行了一些更改,如下所示:

    var blobName = 'BlobName';
    blobService.getBlobToText(
        containerName,
        blobName,
        function(err, blobContent, blob) {
            if (err) {
                console.error("Couldn't download blob %s", blobName);
                console.error(err);
            } else {
                console.log("Sucessfully downloaded blob %s", blobName);
                console.log(blobContent);
            }
        });
    
    Converting to the stream as below:
    
    
    module.exports = async function (context, myBlob) {
        context.log(context.bindings.myBlob.toString());
        context.log("Blob:", context.bindingData.blobTrigger, "\n Blob Size:", myBlob.length, "Bytes");
    };
    

    还可以查看SO 了解更多信息。

    【讨论】:

    • 我试过了,但是没用
    • @cesarandavisa 我可以知道您遇到的错误吗?
    猜你喜欢
    • 1970-01-01
    • 2021-01-17
    • 2023-03-22
    • 1970-01-01
    • 2021-10-13
    • 2019-01-02
    • 1970-01-01
    • 2022-01-08
    • 2021-12-10
    相关资源
    最近更新 更多