具有特定文件名和 Safari 或 Chrome 的 ASP.NET MVC FileResult
我在 FileResult 返回具有特定文件名的文件时遇到问题。在数据库中,文件名只是 ID + 扩展名(例如:456789.mp3)
这段代码
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
return File(fs, "application/octet-stream", "myfile.mp3");
适用于除 Webkit 浏览器(Chrome、Safari)之外的所有浏览器。 Chrome 和 Safari 以原始文件名 (456789.mp3) 接收文件。当我使用 Safari 添加标头时,
Response.AppendHeader("Content-Disposition", "attachment;filename=myfile.mp3");
会收到文件为 myfile.mp3attach(请注意“attach”附加到扩展名?),但是 Chrome 会收到此文件为 myfile.mp3,attach(它将“,attach”附加到扩展名)
有没有人经历过有这样的问题吗?
谢谢
I'm having problems with FileResult returning a file with a specific filename. In the database the filename is just and ID + extension (e.g: 456789.mp3)
This piece of code
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
return File(fs, "application/octet-stream", "myfile.mp3");
Work well in every browser except Webkit browsers (Chrome, Safari). Chrome and Safari receive files as original filename (456789.mp3). When I add headers with
Response.AppendHeader("Content-Disposition", "attachment;filename=myfile.mp3");
Safari receives the file as myfile.mp3attach (notice "attach" appended to the extension?), however Chrome receives this file as myfile.mp3,attach (it appends ",attach" to the extension)
Has anyone experienced this kind of a problem?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它帮助了我:
It has helped me:
Putting
Before
为我解决了这个问题
Putting
Before
solved this for me