我应该为 CSV 使用什么 MIME 类型?
我见过使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
RFC 7111
有一个 RFC 涵盖它并表示使用
text/csv
。此 RFC 更新了 RFC 4180。
Excel
最近我发现了 Excel application/vnd.ms-excel 的显式 mimetype。它于 96 年在 IANA 注册。请注意人们对受发件人摆布以及您的机器受到侵犯的担忧。
我不知道允许供应商扩展。查看此答案了解更多信息- 感谢 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.
I wasn't aware that vendor extensions were allowed. Check out this answer to find out more - thanks starbeamrainbowlabs for the reference.
您应该根据 RFC 4180 使用“text/csv”。
You should use "text/csv" according to RFC 4180.
我的用户可以上传 CSV 文件,但
text/csv
和application/csv
目前尚未出现。这些是通过finfo()识别的:而这些是通过浏览器传输的:
以下类型没有出现,但可以:
My users are allowed to upload CSV files and
text/csv
andapplication/csv
did not appear by now. These are the ones identified through finfo():And these are the ones transmitted through the browser:
The following types did not appear, but could:
MS Excel
的奇怪行为:如果我导出为“基于文本的逗号分隔格式(
csv
)”,这是我在网络服务器上上传后得到的 mime 类型:所以微软似乎再次在做自己的事情,无论现有的如何标准: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:So Microsoft seems to be doing own things again, regardless of existing standards: https://en.wikipedia.org/wiki/Comma-separated_values
对于任何在
*.csv
文件中遇到 Google API mimeType 问题的人,我找到了 google api 文档文件的 MIME 类型列表text/html< /代码>
application/zip
text/plain
application/rtf
application/vnd.oasis.opendocument.text
申请/pdf
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/epub+zip
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/x-vnd.oasis.opendocument.spreadsheet
申请/pdf
text/csv
text/tab-separated-values
application/zip
image/jpeg
图像/png
图像/svg+xml
application/pdf
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.oasis.opendocument.presentation
申请/pdf
text/plain
application/vnd.google-apps.script+json
来源:
https://developers.google.com/drive/v3/web/manage -downloads#downloading_google_documents
下表:
“Google Doc 格式和支持的导出 MIME 类型相互映射如下”
还有另一个列表
application/vnd.google-apps.audio
application/vnd.google-apps.document
application/vnd.google-apps.drawing
application/vnd.google-apps.file
代码>application/vnd.google-apps.folder
application/vnd.google-apps.form
application/vnd.google-apps.fusiontable
application/vnd.google-apps.map
application/vnd.google-apps.photo
application/vnd.google-apps.presentation
application/vnd.google-apps.script
application/vnd.google-apps.site< /code>
application/vnd.google-apps.spreadsheet
application/vnd.google-apps.unknown
application/vnd.google-apps.video
application/vnd.google-apps.drive-sdk
来源:
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 filestext/html
application/zip
text/plain
application/rtf
application/vnd.oasis.opendocument.text
application/pdf
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/epub+zip
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/x-vnd.oasis.opendocument.spreadsheet
application/pdf
text/csv
text/tab-separated-values
application/zip
image/jpeg
image/png
image/svg+xml
application/pdf
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.oasis.opendocument.presentation
application/pdf
text/plain
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
application/vnd.google-apps.audio
application/vnd.google-apps.document
application/vnd.google-apps.drawing
application/vnd.google-apps.file
application/vnd.google-apps.folder
application/vnd.google-apps.form
application/vnd.google-apps.fusiontable
application/vnd.google-apps.map
application/vnd.google-apps.photo
application/vnd.google-apps.presentation
application/vnd.google-apps.script
application/vnd.google-apps.site
application/vnd.google-apps.spreadsheet
application/vnd.google-apps.unknown
application/vnd.google-apps.video
application/vnd.google-apps.drive-sdk
Source here:
https://developers.google.com/drive/v3/web/mime-types
But the first one was more helpful for my use case.
其他答案不完整。
RFC4180 说:
,因此作为文本文件,您应该注意 CSV 文件的编码。如果您的 CSV 文件包含任何重音字符,甚至是欧元符号,则必须指定编码。传递类似:
巴西 Excel 以 Windows-1252 编码(类似于 iso8859-1)导出 CSV 文件,因此您应该声明:
如果您希望它在另一端正确解码。如今,每个文本数据都应该有一个关联的编码。
Other answers are incomplete.
RFC4180 says:
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:
Brazilian Excel exports CSV files in Windows-1252 encoding (similar to iso8859-1), so you should declare:
If you want it correctly decoded in the other side. Nowadays every text data should have an associated encoding.