Javascript 在Azure函数中使用node作为响应发送zip文件的最佳方法?
使用Azure function app,我希望能够将不同URL的图像下载到特定文件夹中,对其进行压缩,并在响应中发送回压缩文件 我可以通过以下步骤实现这一点:Javascript 在Azure函数中使用node作为响应发送zip文件的最佳方法?,javascript,node.js,zip,azure-functions,Javascript,Node.js,Zip,Azure Functions,使用Azure function app,我希望能够将不同URL的图像下载到特定文件夹中,对其进行压缩,并在响应中发送回压缩文件 我可以通过以下步骤实现这一点: 对文件的请求 在本地保存文件 使用Zip压缩目录 archiver读取压缩文件,将其转换为base64 在响应体中发送缓冲区 下载并保存图像 const img = await request(url, { encoding: "binary" }); fs.writeFile(filesName, data, "binary", er
const img = await request(url, { encoding: "binary" });
fs.writeFile(filesName, data, "binary", err => {
if (err) {
reject(`Error while writing the file; ${err}`);
} else {
resolve(data);
}
});
压缩目录,读取压缩文件并发送响应
const target = await zipDirectory(dirName, targetFile);
context.log('Target ' + targetFile);
const rawFile = await readFile(targetFile);
const fileBuffer = Buffer.from(rawFile, "base64");
context.res = {
body: fileBuffer,
headers: {
"Content-Disposition": `filename=target.zip`,
"Content-Type": "application/zip"
},
status: 202
};
有更好的方法吗
http
触发器的函数,其中输入是图像的uri,输出绑定是blob容器。逻辑是将图像保存在blob存储器中