Azure 存储下载到 Blob 过早结束函数应用程序调用

Azure Storage Download to Blob prematurely ends Function App call

我正在使用 Nodejs 将文件下载到缓冲区以用于在我的代码中进行处理。相关代码为

        let bbc = containerClient.getBlockBlobClient(
            userId + "/" + documentUuids[i] + ".pdf"
        );

        let blob;
        try {
            console.log("downloading blob")
            blob = await bbc.downloadToBuffer();
            console.log("downloaded blob ")
        } catch (e) {
            console.log(userId + "/" + documentUuids[i] + ".pdf")
            console.log(e);
        }

但是,blob = await bbc.downloadToBuffer(); 行没有等待下载然后继续其余代码,而是过早地结束了函数 app 和 returns 没有正文的 200。然后我在控制台中看到消息

Warning: Unexpected call to 'log' on the context object after function execution has completed. Please check for asynchronous calls that are not awaited or calls to 'done' made before function execution completes. Function name: BasketsCreateUpdate. Invocation Id: 59f57785-6390-4b93-a69e-8244dc688d37. Learn more: https://go.microsoft.com/fwlink/?linkid=2097909 

最终在我的日志中,我看到了所需的输出,但该函数已经过早地返回了一个空体。我不知道为什么会这样,如果有任何帮助,我将不胜感激。

您的 blob 下载代码没有任何问题,我假设您在 js 函数中处理结果应该有问题。我写了一个简单的演示,为您获取.txt 的内容,可以满足您的要求:

module.exports = async function (context, req) {
    
    const { BlobServiceClient, StorageSharedKeyCredential } = require("@azure/storage-blob");
    const account = ''
    const accountKey = ''
    const container = ''
    const blobName = ''

    async function test(context){
        const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
    
        const blobServiceClient = new BlobServiceClient(
            `https://${account}.blob.core.windows.net`,
            sharedKeyCredential
        );
    
        const bbc = blobServiceClient.getContainerClient(container).getBlockBlobClient(blobName);
        context.log('=================> download start');
        let blob = await bbc.downloadToBuffer();
        context.log('=================> download complete');
    
        return blob.toString('utf-8');
    
    }

    var result = await test(context);
    

    context.res = {       
        body: result
    };
}

结果: