有没有办法找出MIME类型(或者叫做"Content- type "?)Linux bash脚本中的文件?
我需要它的原因是因为ImageShack似乎需要它来上传文件,因为出于某种原因,它将.png文件检测为application/octet-stream
文件。
我检查了这个文件,它确实是一个PNG图像:
$ cat /1.png
?PNG
(with a heap load of random characters)
这给了我一个错误:
$ curl -F "fileupload=@/1.png" http://www.imageshack.us/upload_api.php
<links>
<error id="wrong_file_type">Wrong file type detected for file 1.png:application/octet-stream</error>
</links>
这是可行的,但我需要指定一个MIME类型。
$ curl -F "fileupload=@/1.png;type=image/png" http://www.imageshack.us/upload_api.php
发布于 2010-02-09 14:25:22
使用file
。示例:
> file --mime-type image.png
image.png: image/png
> file -b --mime-type image.png
image/png
> file -i FILE_NAME
image.png: image/png; charset=binary
发布于 2010-02-09 14:25:45
您可以使用的另一个工具(除文件外)是xdg-mime
例如xdg-mime query filetype <file>
如果你有美味,
yum install xdg-utils.noarch
子(字幕)文件上xdg-mime和file的比较示例
$ xdg-mime query filetype subtitles.srt
application/x-subrip
$ file --mime-type subtitles.srt
subtitles.srt: text/plain
在上面的文件中,只将其显示为纯文本。
发布于 2010-02-09 14:26:19
尝试使用带有-i
选项的file
命令。
-i
选项使file命令输出mime类型的字符串,而不是更传统的人类可读的字符串。因此,它可能会说text/plain; charset=us-ascii
而不是ASCII text
。
https://stackoverflow.com/questions/2227182
复制相似问题