About TSV files
Like CSV, but with tabs between fields, which avoids most quoting problems because tabs rarely appear in data. This is what you get when you copy cells from a spreadsheet, and what many database and bioinformatics tools export.
File signature
TSV has no fixed signature: it is text without a magic number, so validate uploads by parsing the content rather than by checking bytes.
Serve .tsv with the right Content-Type
Content-Type: text/tab-separated-values; charset=utf-8
text/tab-separated-values tsv tab;
AddType text/tab-separated-values .tsv .tab
AddCharset UTF-8 .tsv .tab
@tsv path *.tsv *.tab
header @tsv Content-Type "text/tab-separated-values; charset=utf-8"
curl -sI https://example.com/file.tsv | grep -i '^content-type'
# Content-Type: text/tab-separated-values; charset=utf-8
Set the type in code
res.set('Content-Type', 'text/tab-separated-values; charset=utf-8');
import mimetypes
mimetypes.add_type('text/tab-separated-values', '.tsv') # if your system doesn't know it
mimetypes.guess_type('file.tsv')[0] # 'text/tab-separated-values'
mime.AddExtensionType(".tsv", "text/tab-separated-values; charset=utf-8")
w.Header().Set("Content-Type", "text/tab-separated-values; charset=utf-8")
Accept .tsv uploads
<input type="file" accept=".tsv,.tab,text/tab-separated-values">
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
-
.csv (
text/csv): CSV -
.txt (
text/plain): Plain text -
.xlsx (
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet): Excel workbook
More data and text
.md , .json , .ndjson , .jsonld , .xml , .yaml , .geojson , .ics , .sql . 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 .tsv files?
text/tab-separated-values. It is a text format, so add the character set: "Content-Type: text/tab-separated-values; charset=utf-8".
Why does my server send the wrong Content-Type for .tsv?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .tsv 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 TSV?
TSV has no fixed file signature, so the extension and content are all you have. Check that the content is what you expect, for example by parsing it, before trusting an upload.