如何通过流获取文件

how to get the file via stream

我的 file/image 存储在 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;
}

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

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");
    }
}