1

我的文件/图像存储在 Azure 存储中,但我需要通过流发送文件(而不是在本地下载文件)

import storage from 'azure-storage';

const Storage = storage.createBlobService();

async handler(request,h){
const photo = new Promise((resolve, reject) => {
    const res = Storage.createReadStream('conatinername',
      'file.jpg');

    res.on('data', () => { });

    res.on('readable', (data) => resolve(data));
  });

  return await photo;
}
4

1 回答 1

0

假设您想发送图像作为响应,请尝试下面的处理程序。

handler: async function(request,h) {
    const photo = new Promise((resolve, reject) => {
        const res = Storage.createReadStream(containerName, blobName);
        res.on('data', (data) => resolve(data));
        res.on('error',(err) => reject(err));
    });
    try {
        var content = await photo;
        return h.response(content).type('image/jpg');
    } catch(err){
        return h.response("ERROR Downloading");
    }
}
于 2019-01-14T07:59:46.293 回答