Node.js/下载
来自康健生活
< Node.js
标题文字
其他
...
/**
* 获取内容
*/
async processAction() {
const { namespace, filepath } = this.get();
const fileMd5 = this.getFileKey(['pkg', namespace, filepath].join('/'));
const content = await storeInstance.get(fileMd5, {
key: fileMd5,
ip: this.ip,
namespace: this.get().namespace
}).catch(err => err);
if (think.isError(content)) {
return Promise.reject(content);
}
const buffer = Buffer.from(content, 'base64');
this.header('Cache-Control', `max-age=600,s-maxage=86400`);
// 二进制,会直接下载文件,如果是二进制等浏览器无法解析的文件,浏览器会直接下载该文件
// this.body = buffer;
// 浏览器打开文件
this.body = buffer.toString();
}
...
No categories