接口返回的二进制文件报格式错误
aoxls opened this issue · comments
aoxls commented
我写了一个导出excel的功能,导出csv可以正常打开,xlsx的话就会报格式错误无法打开,用stream或者buffer都一样。试了一下好像纯文本格式的都正常,其他二进制的格式可能都有问题,请问需要做什么处理吗?
export const test = Api(
Get(`/test`),
Query<any>(),
async () => {
const ctx = useContext<Context>()
const file = fs.createReadStream('./test.zip', 'utf8')
ctx.type = 'zip'
ctx.set('Content-disposition', `attachment; filename=test.zip`)
ctx.statusCode = 200
ctx.body = file
}
)