About MP3 audio files
The registered type is audio/mpeg; audio/mp3 is a widespread mistake that browsers tolerate. For seeking in <audio> to work, the server must support range requests (Accept-Ranges: bytes and 206 responses).
Other types seen for these files:
audio/mp3
,
audio/mpeg3
. Accept them when reading uploads, but send audio/mpeg yourself.
File signature
MP3 files start with 49 44 33 ("ID3" tag), or FF FB / FF F3 / FF F2 (frame sync) without tags. The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .mp3 with the right Content-Type
Content-Type: audio/mpeg
audio/mpeg mp3;
AddType audio/mpeg .mp3
@mp3 path *.mp3
header @mp3 Content-Type "audio/mpeg"
curl -sI https://example.com/file.mp3 | grep -i '^content-type'
# Content-Type: audio/mpeg
Set the type in code
res.set('Content-Type', 'audio/mpeg');
// Or make the browser download it:
res.attachment('file.mp3');
import mimetypes
mimetypes.add_type('audio/mpeg', '.mp3') # if your system doesn't know it
mimetypes.guess_type('file.mp3')[0] # 'audio/mpeg'
mime.AddExtensionType(".mp3", "audio/mpeg")
w.Header().Set("Content-Type", "audio/mpeg")
Accept .mp3 uploads
<input type="file" accept=".mp3,audio/mpeg">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
-
.m4a (
audio/mp4): M4A audio -
.ogg (
audio/ogg): Ogg audio -
.wav (
audio/wav): WAV audio -
.aac (
audio/aac): AAC audio
More audio
.flac . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .mp3 files?
audio/mpeg. You may also see audio/mp3, audio/mpeg3, which are older or unofficial; send audio/mpeg. The full header is "Content-Type: audio/mpeg".
Why does my server send the wrong Content-Type for .mp3?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .mp3 is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is MP3?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. MP3 files start with 49 44 33 ("ID3" tag), or FF FB / FF F3 / FF F2 (frame sync) without tags. The MIME type lookup on this site reads them for you when you drop a file on it.