About MPEG transport stream files
Web servers map .ts to video/mp2t, the format of HLS video segments and broadcast TV. That clashes with TypeScript source files: a .ts file served from a dev server or CDN arrives as video. Browsers never run TypeScript directly, so serve compiled .js; if you must serve TypeScript source (for example to Deno), configure text/typescript or application/typescript for that path, neither of which is registered.
File signature
TS files start with 0x47 sync byte at the start of every 188-byte packet. 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 .ts with the right Content-Type
Content-Type: video/mp2t
video/mp2t ts;
AddType video/mp2t .ts
@ts path *.ts
header @ts Content-Type "video/mp2t"
curl -sI https://example.com/file.ts | grep -i '^content-type'
# Content-Type: video/mp2t
Set the type in code
res.set('Content-Type', 'video/mp2t');
// Or make the browser download it:
res.attachment('file.ts');
import mimetypes
mimetypes.add_type('video/mp2t', '.ts') # if your system doesn't know it
mimetypes.guess_type('file.ts')[0] # 'video/mp2t'
mime.AddExtensionType(".ts", "video/mp2t")
w.Header().Set("Content-Type", "video/mp2t")
Accept .ts uploads
<input type="file" accept=".ts,video/mp2t">
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
-
.m3u8 (
application/vnd.apple.mpegurl): HLS playlist -
.mp4 (
video/mp4): MP4 video -
.js (
text/javascript): JavaScript
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 .ts files?
video/mp2t. The full header is "Content-Type: video/mp2t".
Why does my server send the wrong Content-Type for .ts?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .ts 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 TS?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. TS files start with 0x47 sync byte at the start of every 188-byte packet. The MIME type lookup on this site reads them for you when you drop a file on it.