content type for mp3 download response
Asked Answered
A

7

54

I have created a simple HTTP server which allows users to download files. But this does not seem to work for mp3 files. The content type currently is "application/misc". In order to make it work with mp3 files , I've tried "application/mp3" , "application/data" and "application/mpeg".

What would be the right content type for mp3 or audio file download, and am I missing some other headers?


EDIT: The file should automatically start downloading rather than prompting the user for saving it somewhere.

Arcanum answered 18/8, 2012 at 10:9 Comment(1)
This question actually consists of two questions which were asked earlier: Which mime type should I use for mp3 and Forcing to download a file using PHP. As for save dialog, this is not under your control.Irs
C
93

Try "Content-Type: audio/mpeg"

Update

To encourage the browser to download the mp3 rather then streaming, do

Content-Disposition: filename="music.mp3"'

Carlisle answered 18/8, 2012 at 10:13 Comment(5)
Yeah I tried that too , but it starts streaming it. I want the file to get downloaded.Arcanum
Are you setting more than 1 content type header?Carlisle
As of now I m just using only one header i.e Content-Type. I guess Content-Disposition header would prompt user to save the file. I require the file to automatically start downloading.Arcanum
My mp3 gets downloaded, but now it's zero KB. Any ideas? File on the server is 3MB so it should work? How does 'filename' find a file anyway?Waly
The correct header for a download is Content-Disposition: attachment; filename="my-file.mp3"Studding
S
11
.mp3    audio/mpeg3
.mp3    audio/x-mpeg-3
.mp3    video/mpeg
.mp3    video/x-mpeg

Using Content-Disposition: attachment... forces a download box to appear instead of having to right click -> save target as.

Spiritoso answered 18/8, 2012 at 10:15 Comment(1)
I've also seen audio/mpegStraightout
J
3

After a lot of research, I found some resources (some on SO) that led to this solution. It is the most cross device compatible solution out there and solves a lot of issues especially with Android devices (a lot of issues with them apparently).

Content-Disposition: attachment; filename="my_mp3_filename.MP3"

Take note of the upper-case extension. That is important.

Jive answered 7/11, 2014 at 20:9 Comment(0)
A
1

Using Content-Type "application/force-download" worked for me.

Arcanum answered 21/8, 2012 at 9:58 Comment(1)
The browser doesn't know how to display that content type inline, so the user has to download it (and decide what application is appropriate to play it). It'd be the same as doing: Content-Type: application/garbageScopolamine
R
1

try below content type it worked for me.

"audio/mpeg3;audio/x-mpeg-3;video/mpeg;video/x-mpeg;text/xml"
Rein answered 26/5, 2013 at 14:2 Comment(0)
O
0

set "content-disposition" as "attachment

Obstipation answered 18/8, 2012 at 10:18 Comment(0)
S
0

To enable downloading instead of streaming try 'Content-Disposition': 'attachment; filename="name.mp3"'

Saprophagous answered 26/9, 2023 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.