set header不适用于nodejs中的文件名 [英] set header not working for filename in nodejs

查看:262
本文介绍了set header不适用于nodejs中的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有uploded文件名被加密,所以当我想下载这些文件我正在更改文件名与实际的文件名保存在数据库,下面的代码应该工作,但不是在我的情况下,
如何在下载



下面更改文件名称

  res.setHeader('Content-Disposition','attachment; filename ='+ fileName +'); 
res.setHeader('Content-Type','image / jpg');
res.download(filepath);

任何帮助都会赞赏,请建议

解决方案

res。下载()在我的情况下不工作

  res.get('/ download',function(req,res ){
res.download(__ dirname +'jsonFile.json','jsonFile.json');
});


all uploded file name are encrypted , so when i want to download those file i am changing file name with there actual file name which are saved in data base, below code should work but not in my case, how to change file name while downloading

below is my code for it

res.setHeader('Content-Disposition', 'attachment;filename="' + fileName + '"');
res.setHeader('Content-Type', 'image/jpg' );
res.download(filepath);

any help will b appreciated , please suggest

解决方案

res.download() not working in my case

res.get('/download', function(req, res) {
  res.download(__dirname + 'jsonFile.json', 'jsonFile.json');
});

这篇关于set header不适用于nodejs中的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆