描述:我无法从缓冲区返回StreamableFile,我尝试了buffer.from
,但不起作用,这显示了下面的错误
问题的法语版本:Aucune附加费与上诉相对应。附加费1 sur 2,"(缓冲区:缓冲区(:可流文件",一个générél’erreur suivante。"string"类型的参数是"Buffer"类型参数的属性。附加费2 sur 2,"(可读:可读(:可流文件",一个générél’erreur suivante。"字符串"类型的参数是"可读"类型参数的属性。ts(2769(。
问题的英文版:没有与此调用匹配的过载。第1个(共2个(重载"(缓冲区:缓冲区(:StreamableFile"生成了以下错误。类型为"string"的参数不可分配给类型为"Buffer"的参数。第2个(共2个(重载"(可读:可读(:StreamableFile"生成了以下错误。类型为"string"的参数不可分配给类型为"Readable"的参数。ts(2769(
async FindCommands(@Res({ passthrough: true }) response, @Query() query: DateRangQueryVm): Promise<StreamableFile> {
const filesToPdf= await this.commandsService.getCommands(query.startDate, query.endDate);
const nommation= `commands.pdf`;
response.setHeader('Content-Type', `application/pdf`);
response.setHeader('Content-Disposition', `attachment; filename=${nommation}`);
Buffer.from(filesToPdf, 'utf-8');
return new StreamableFile(filesToPdf);
};
返回新的StreamableFile(filesToPdf(
嵌套文档链接:
https://docs.nestjs.com/techniques/streaming-files#streaming-文件
错误是明确的:不能将string
传递给StreamableFile
,必须传递Buffer
或Readable
。要从字符串创建缓冲区,可以使用return new StreamableFile(Buffer.from(filesToPdf))