Safari and downloading file issue
I have a website where I let users download mp3 files. The code snippet (partial) is as follows:
Response.Clear();
Response.AppendHeader("Content-Disposition:", "attachmen开发者_运维技巧t; filename=mike.mp3");
Response.AppendHeader("Content-Length", "1000");
Response.ContentType = "audio/mpeg3";
A customer complained that he is unable to download this file on Safari on Mac 10.4.11. (It simply renders the mp3 file on the page) So, I downloaded Safari for Windows and am unable to recreate the issue. So, I guess there's a difference between Safari for Windows and Safari for Mac?
I don't have a Mac machine. How do I troubleshoot this issue?
Maybe the colon after header name?
Yes, that certainly shouldn't be there.
Plus, the proper MIME media type for MP3 is audio/mpeg
. This type covers the tightly-related MPEG layer-1, layer-2 (.mp2) and layer-3 (.mp3) formats (but not MPEG-4 AAC which is quite different).
Browsers won't recognise the non-standard (not registered with IANA) audio/mpeg3
type, so it's anyone's guess how they'll choose to handle them. It often involves some spooky content-sniffing guesswork, unfortunately, which can lead to quite inappropriate results when browsers see a spurious string they think is evidence of one (wrong) type of file.
Interesting. I don't have asp.net, so I have created this Python web application:
#!/usr/bin/env python
import werkzeug
@werkzeug.Request.application
def app(request):
f = open("audio.mp3")
r = werkzeug.Response(f, content_type="audio/mpeg3")
r.headers.add("Content-Disposition", "attachment; filename=mike.mp3")
r.headers.add("Content-Length", "1000")
return r
werkzeug.run_simple("localhost", 4000, app)
Even when the Content-Type (and Content-Length) is wrong, Safari just downloads the file. I have Safari Version 4.0.4 (6531.21.10) on Mac OS X 10.6.2.
精彩评论