About HLS playlist files
An .m3u8 file is a text playlist that points to short video segments (.ts or fMP4). Safari plays HLS natively in <video>; other browsers need a library such as hls.js. Players cross-origin need CORS headers on both the playlist and the segments, and the playlist should not be cached for long during live streams.
Other types seen for these files:
application/x-mpegURL
,
audio/mpegurl
. Accept them when reading uploads, but send application/vnd.apple.mpegurl yourself.
File signature
M3U8 files start with "#EXTM3U". 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 .m3u8 with the right Content-Type
Content-Type: application/vnd.apple.mpegurl; charset=utf-8
application/vnd.apple.mpegurl m3u8;
AddType application/vnd.apple.mpegurl .m3u8
AddCharset UTF-8 .m3u8
@m3u8 path *.m3u8
header @m3u8 Content-Type "application/vnd.apple.mpegurl; charset=utf-8"
curl -sI https://example.com/file.m3u8 | grep -i '^content-type'
# Content-Type: application/vnd.apple.mpegurl; charset=utf-8
Set the type in code
res.set('Content-Type', 'application/vnd.apple.mpegurl; charset=utf-8');
import mimetypes
mimetypes.add_type('application/vnd.apple.mpegurl', '.m3u8') # if your system doesn't know it
mimetypes.guess_type('file.m3u8')[0] # 'application/vnd.apple.mpegurl'
mime.AddExtensionType(".m3u8", "application/vnd.apple.mpegurl; charset=utf-8")
w.Header().Set("Content-Type", "application/vnd.apple.mpegurl; charset=utf-8")
Accept .m3u8 uploads
<input type="file" accept=".m3u8,application/vnd.apple.mpegurl">
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
-
.ts (
video/mp2t): MPEG transport stream -
.mp4 (
video/mp4): MP4 video -
.vtt (
text/vtt): WebVTT subtitles
More video
.webm , .mov , .avi , .mkv . 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 .m3u8 files?
application/vnd.apple.mpegurl. You may also see application/x-mpegURL, audio/mpegurl, which are older or unofficial; send application/vnd.apple.mpegurl. It is a text format, so add the character set: "Content-Type: application/vnd.apple.mpegurl; charset=utf-8".
Why does my server send the wrong Content-Type for .m3u8?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .m3u8 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 M3U8?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. M3U8 files start with "#EXTM3U". The MIME type lookup on this site reads them for you when you drop a file on it.