What MIME type should I use for CSV?

CsvHttp HeadersMime TypesContent Type

Csv Problem Overview


I've seen application/csv used and also text/csv.

Is there a difference? Does it matter which as long as the request matches something that's available? Are they interchangeable?

Csv Solutions


Solution 1 - Csv

RFC 7111

There is an RFC which covers it and says to use text/csv.

This RFC updates RFC 4180.


Excel

Recently I discovered an explicit mimetype for Excel application/vnd.ms-excel. It was registered with IANA in '96. Note the concerns raised about being at the mercy of the sender and having your machine violated.

>

Media Type: application/vnd.ms-excel
> > Name Microsoft Excel (tm) > > Required parameters: None > > Optional parameters: name > > Encoding considerations: base64 preferred > > Security considerations: As with most application types this data is > intended for interpretation by a program that understands the data on > the recipient's system. Recipients need to understand that they are at > the "mercy" of the sender, when receiving this type of data, since > data will be executed on their system, and the security of their > machines can be violated. > > OID { org-id ms-files(4) ms-excel (3) } > > Object type spreadsheet > > Comments This Media Type/OID is used to identify Microsoft > Excel generically (i.e., independent of version, subtype, or platform format).

I wasn't aware that vendor extensions were allowed. Check out this answer to find out more - thanks starbeamrainbowlabs for the reference.

Solution 2 - Csv

You should use "text/csv" according to RFC 4180.

Solution 3 - Csv

Strange behavior with MS Excel: If i export to "text based, comma-separated format (csv)" this is the mime-type I get after uploading on my webserver:

[name] => data.csv
[type] => application/vnd.ms-excel

So Microsoft seems to be doing own things again, regardless of existing standards: https://en.wikipedia.org/wiki/Comma-separated_values

Solution 4 - Csv

My users are allowed to upload CSV files and text/csv and application/csv did not appear by now. These are the ones identified through finfo():

text/plain
text/x-csv

And these are the ones transmitted through the browser:

text/plain
application/vnd.ms-excel
text/x-csv

The following types did not appear, but could:

application/csv
application/x-csv
text/csv
text/comma-separated-values
text/x-comma-separated-values
text/tab-separated-values

Solution 5 - Csv

For anyone struggling with Google API mimeType for *.csv files, I have found the list of MIME types for google api docs files

Google Doc Format Conversion Format Corresponding MIME type
Documents HTML text/html
HTML (zipped) application/zip
Plain text text/plain
Rich text application/rtf
Open Office doc application/vnd.oasis.opendocument.text
PDF application/pdf
MS Word document application/vnd.openxmlformats-officedocument.wordprocessingml.document
EPUB application/epub+zip
Spreadsheets MS Excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Open Office sheet application/x-vnd.oasis.opendocument.spreadsheet
PDF application/pdf
CSV (first sheet only) text/csv
TSV (first sheet only) text/tab-separated-values
HTML (zipped) application/zip
Drawings JPEG image/jpeg
PNG image/png
SVG image/svg+xml
PDF application/pdf
Presentations MS PowerPoint application/vnd.openxmlformats-officedocument.presentationml.presentation
Open Office presentation application/vnd.oasis.opendocument.presentation
PDF application/pdf
Plain text text/plain
Apps Scripts JSON application/vnd.google-apps.script+json

Source here: https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents the table under: "Google Doc formats and supported export MIME types map to each other as follows"

There is also another list

MIME Type Description
application/vnd.google-apps.audio
application/vnd.google-apps.document Google Docs
application/vnd.google-apps.drawing Google Drawing
application/vnd.google-apps.file Google Drive file
application/vnd.google-apps.folder Google Drive folder
application/vnd.google-apps.form Google Forms
application/vnd.google-apps.fusiontable Google Fusion Tables
application/vnd.google-apps.map Google My Maps
application/vnd.google-apps.photo
application/vnd.google-apps.presentation Google Slides
application/vnd.google-apps.script Google Apps Scripts
application/vnd.google-apps.site Google Sites
application/vnd.google-apps.spreadsheet Google Sheets
application/vnd.google-apps.unknown
application/vnd.google-apps.video
application/vnd.google-apps.drive-sdk 3rd party shortcut

Source here: https://developers.google.com/drive/v3/web/mime-types

But the first one was more helpful for my use case.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSteve DunnView Question on Stackoverflow
Solution 1 - CsvChris McCauleyView Answer on Stackoverflow
Solution 2 - CsvSmokefootView Answer on Stackoverflow
Solution 3 - CsvRobertView Answer on Stackoverflow
Solution 4 - CsvmguttView Answer on Stackoverflow
Solution 5 - CsvLuckylookeView Answer on Stackoverflow