【发布时间】:2021-03-20 19:08:39
【问题描述】:
我正在使用 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(); 行提前结束了函数应用程序并返回没有正文的 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
最终在我的日志中,我看到了所需的输出,但该函数已经过早地返回了一个空主体。我不知道为什么会这样,如果有任何帮助,我将不胜感激。
【问题讨论】:
-
您的代码没有问题。我可能正在某个地方发生。你能发布整个函数以及它是如何使用的吗?
-
怎么样?你的问题解决了吗?
-
嗨!是的,我们修好了。我们在导致问题的代码的其他地方链接了多个 .then()。用 await 重构它们解决了我们的问题
-
很高兴知道您的问题已经解决。如果我的帖子有帮助,请点击答案旁边的复选标记,将其从灰色切换为已填充以接受它作为答案,所以它将帮助其他人并关闭此查询:)
标签: node.js azure-blob-storage azure-function-app