以下是我从我的服务器中用sailsJS编写文件的功能。当我尝试运行此功能时,控制台会向我抛出此类错误:TypeError: The header content contains invalid characters
在邮递员中,我以pdf格式发送文件,
内容类型在这里看起来如何?
fn: async function ({ id }, exits) {
this.res.set('Content-disposition', `attachment; filename=${id}`, 'content-type', 'application/pdf')//here
this.res.set('Access-Control-Allow-Origin', '*')
const localPath = path.join(sails.config.custom.uploadDirectory, id)
this.res.sendFile(localPath);
}
预先感谢
根据SailJS Documentation here,您可以一次将单个对象参数(标题)传递给设置多个标题字段,其中keys
是标题字段名称,而对应的values
是所需的值。
我认为您没有以正确的方式设置标题值。
如果设置多个值,它应该发送完整的对象:
res.set({
'Content-disposition': 'attachment',
'content-type': 'application/pdf',
'filename'= 'filename.pdf'
})