我的文件/图像存储在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;
}
答案 0 :(得分: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");
}
}