Azure函数-读取Blob数据[JS]

时间:2020-09-22 10:13:00

标签: azure azure-functions azure-storage-blobs

我正在尝试使用azure函数读取天蓝色blob内容。

var blobName = 'my-awesome-text-blob';
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);
        }
    });

容器名称始终相同,并且通过触发该功能的队列消息传递blob名称。

运行此函数时,该函数超时(超过5分钟)。

具有blob名称的队列消息正确并显示,该blob仅包含一个长json,大约292kb。

我试图在创建新的blob时直接触发该函数,但是它返回带有流的对象,您知道有什么方法可以使该流可读吗?

module.exports = async function (context, myBlob) {
    context.log("JavaScript blob trigger function processed blob \n Blob:", context.bindingData.blobTrigger, "\n Blob Size:", myBlob.length, "Bytes");
    context.log("type of the blob passed:",typeof(myBlob))

使用上面的代码,我正确地获得了blob的类型和长度。

但是如果我尝试打印它,我会得到:

( 2020-09-22 [Information] printing blob <Buffer 7b ....... )

谢谢您的帮助。

1 个答案:

答案 0 :(得分:1)

只需转换流:

module.exports = async function (context, myBlob) {
    context.log(context.bindings.myBlob.toString());
    context.log("JavaScript blob trigger function processed blob \n Blob:", context.bindingData.blobTrigger, "\n Blob Size:", myBlob.length, "Bytes");
};