我应该为 CSV 使用什么 MIME 类型?

发布于 2024-11-29 15:49:50 字数 107 浏览 2 评论 0原文

我见过使用 application/csv 以及 text/csv

有区别吗?只要请求与可用的内容匹配,这是否重要?它们可以互换吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

So尛奶瓶 2024-12-06 15:49:50

RFC 7111

有一个 RFC 涵盖它并表示使用 text/csv

此 RFC 更新了 RFC 4180。

Excel

最近我发现了 Excel application/vnd.ms-excel 的显式 mimetype。它于 96 年在 IANA 注册。请注意人们对受发件人摆布以及您的机器受到侵犯的担忧。

媒体类型:application/vnd.ms-excel

名称 Microsoft Excel (tm)

所需参数:无

可选参数:名称

编码注意事项:首选 base64

安全考虑:与大多数应用程序类型一样,此数据是
旨在由理解数据的程序进行解释
收件人的系统。接收者需要了解他们处于
发送者的“仁慈”,当接收这种类型的数据时,因为
数据将在他们的系统上执行,并且他们的安全性
机器可能会被侵犯。

OID { org-id ms-files(4) ms-excel (3) }

对象类型电子表格

评论 此媒体类型/OID 用于识别 Microsoft
一般 Excel(即,独立于版本、子类型或平台格式)。

我不知道允许供应商扩展。查看此答案了解更多信息- 感谢 starbeamrainbowlabs 提供参考。

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.

兔姬 2024-12-06 15:49:50

您应该根据 RFC 4180 使用“text/csv”。

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

水染的天色ゝ 2024-12-06 15:49:50

我的用户可以上传 CSV 文件,但 text/csvapplication/csv 目前尚未出现。这些是通过finfo()识别的:

text/plain
text/x-csv

而这些是通过浏览器传输的:

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

以下类型没有出现,但可以:

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

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
别低头,皇冠会掉 2024-12-06 15:49:50

MS Excel 的奇怪行为:
如果我导出为“基于文本的逗号分隔格式(csv)”,这是我在网络服务器上上传后得到的 mime 类型:

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

所以微软似乎再次在做自己的事情,无论现有的如何标准:https://en.wikipedia.org/wiki/Comma-separated_values

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

眼中杀气 2024-12-06 15:49:50

对于任何在 *.csv 文件中遇到 Google API mimeType 问题的人,我找到了 google api 文档文件的 MIME 类型列表

Google Doc 格式转换格式相应的 MIME 类型
文档HTMLtext/html< /代码>
HTML(压缩)application/zip
纯文本text/plain
富文本application/rtf
打开 Office 文档application/vnd.oasis.opendocument.text
PDF申请/pdf
MS Word 文档application/vnd.openxmlformats-officedocument.wordprocessingml.document
EPUBapplication/epub+zip
电子表格MS Excelapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
打开 Office 工作表application/x-vnd.oasis.opendocument.spreadsheet
PDF申请/pdf
CSV(仅限第一张)text/csv
TSV(仅限第一张)text/tab-separated-values
HTML(压缩)application/zip
绘图JPEGimage/jpeg
PNG图像/png
SVG图像/svg+xml
PDFapplication/pdf
演示文稿MS PowerPointapplication/vnd.openxmlformats-officedocument.presentationml.presentation
打开 Office 演示文稿application/vnd.oasis.opendocument.presentation
PDF申请/pdf
纯文本text/plain
Apps 脚本JSONapplication/vnd.google-apps.script+json

来源:
https://developers.google.com/drive/v3/web/manage -downloads#downloading_google_documents
下表:
“Google Doc 格式和支持的导出 MIME 类型相互映射如下”

还有另一个列表

MIME 类型描述
application/vnd.google-apps.audio
application/vnd.google-apps.documentGoogle 文档
application/vnd.google-apps.drawingGoogle 绘图
application/vnd.google-apps.file代码>Google 云端硬盘文件
application/vnd.google-apps.folderGoogle 云端硬盘文件夹
application/vnd.google-apps.formGoogle 表单
application/vnd.google-apps.fusiontableGoogle Fusion Tables
application/vnd.google-apps.mapGoogle 我的地图
application/vnd.google-apps.photo
application/vnd.google-apps.presentationGoogle 幻灯片
application/vnd.google-apps.scriptGoogle Apps 脚本
application/vnd.google-apps.site< /code>Google 协作平台
application/vnd.google-apps.spreadsheetGoogle 表格
application/vnd.google-apps.unknown
application/vnd.google-apps.video
application/vnd.google-apps.drive-sdk第 3 方快捷方式

来源:
https://developers.google.com/drive/v3/web/mime-types

但第一个对我的用例更有帮助。

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 FormatConversion FormatCorresponding MIME type
DocumentsHTMLtext/html
HTML (zipped)application/zip
Plain texttext/plain
Rich textapplication/rtf
Open Office docapplication/vnd.oasis.opendocument.text
PDFapplication/pdf
MS Word documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
EPUBapplication/epub+zip
SpreadsheetsMS Excelapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Open Office sheetapplication/x-vnd.oasis.opendocument.spreadsheet
PDFapplication/pdf
CSV (first sheet only)text/csv
TSV (first sheet only)text/tab-separated-values
HTML (zipped)application/zip
DrawingsJPEGimage/jpeg
PNGimage/png
SVGimage/svg+xml
PDFapplication/pdf
PresentationsMS PowerPointapplication/vnd.openxmlformats-officedocument.presentationml.presentation
Open Office presentationapplication/vnd.oasis.opendocument.presentation
PDFapplication/pdf
Plain texttext/plain
Apps ScriptsJSONapplication/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 TypeDescription
application/vnd.google-apps.audio
application/vnd.google-apps.documentGoogle Docs
application/vnd.google-apps.drawingGoogle Drawing
application/vnd.google-apps.fileGoogle Drive file
application/vnd.google-apps.folderGoogle Drive folder
application/vnd.google-apps.formGoogle Forms
application/vnd.google-apps.fusiontableGoogle Fusion Tables
application/vnd.google-apps.mapGoogle My Maps
application/vnd.google-apps.photo
application/vnd.google-apps.presentationGoogle Slides
application/vnd.google-apps.scriptGoogle Apps Scripts
application/vnd.google-apps.siteGoogle Sites
application/vnd.google-apps.spreadsheetGoogle Sheets
application/vnd.google-apps.unknown
application/vnd.google-apps.video
application/vnd.google-apps.drive-sdk3rd party shortcut

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

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

葬﹪忆之殇 2024-12-06 15:49:50

其他答案不完整。

RFC4180 说:

可选参数:字符集、标头

,因此作为文本文件,您应该注意 CSV 文件的编码。如果您的 CSV 文件包含任何重音字符,甚至是欧元符号,则必须指定编码。传递类似:

text/csv; charset=utf-8

巴西 Excel 以 Windows-1252 编码(类似于 iso8859-1)导出 CSV 文件,因此您应该声明:

text/csv; charset=windows-1252

如果您希望它在另一端正确解码。如今,每个文本数据都应该有一个关联的编码。

Other answers are incomplete.

RFC4180 says:

Optional parameters: charset, header

so as a text file, you should take care of the encoding of your CSV file. If your CSV file has any accented char, or even an Euro symbol, encoding specification is a must. Pass something like:

text/csv; charset=utf-8

Brazilian Excel exports CSV files in Windows-1252 encoding (similar to iso8859-1), so you should declare:

text/csv; charset=windows-1252

If you want it correctly decoded in the other side. Nowadays every text data should have an associated encoding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文