[英]Azure function ( blob trigger ) read CSV file with Nodejs
使用 Nodejs 在 azure 函數中讀取 myBlob 緩沖區參數並將其寫入表存儲的最佳方法是什么,因為我正在嘗試使用大小為 16MB 的文件並且它太慢了。
另一件事是當我使用 context.log() 查看文件的內容時,它不會顯示文件的所有內容,而只顯示其中的一部分。
module.exports = async function (context, myBlob) {
let data = myBlob.toString("utf8");
context.log("context", data);
};
您可以在 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以獲取更多見解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.