如何提供来自Azure功能和存储Blob的GET请求



对于这个前端请求<img src="img/abc.png">,我有以下Azure功能(AF(来访问存储Blob 上的图像文件

函数.json

"methods": ["get"],
"route": "img/{filename}"

index.js

const bbc = blobServiceClient.getContainerClient("pngfiles").getBlockBlobClient(context.req.params.filename);  

在这一行之后,我不知道如何读取/获取/流或其他什么来将请求从AF提供给前端。我尝试了以下操作,但它返回元数据和属性

const png = await bbc.download();
context.res = {body: png,  headers: {"Content-Type": "image/png"}};

不确定是否是最佳方式,但有效:

const bbc = await blobServiceClient.getContainerClient("pngfiles").getBlockBlobClient(context.req.params.filename).downloadToBuffer();
context.res = {body: bbc, headers: {"Content-Type": "image/png"}};

最新更新