Min*_*int 91 linux bash mime content-type mime-types
有没有办法找出Linux bash脚本中的文件的MIME类型(或称为"Content-Type"?)?
我需要它的原因是因为ImageShack似乎需要它来上传文件,因为它将某个.png文件检测为application/octet-stream
文件.
我检查了文件,它确实是一个PNG图像:
$ cat /1.png
?PNG
(with a heap load of random characters)
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
$ 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>
Run Code Online (Sandbox Code Playgroud)
这有效,但我需要指定MIME-TYPE.
$ curl -F "fileupload=@/1.png;type=image/png" http://www.imageshack.us/upload_api.php
Run Code Online (Sandbox Code Playgroud)
bhu*_*ups 191
使用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
Run Code Online (Sandbox Code Playgroud)
gho*_*g74 21
您可以使用的另一个工具(除了文件)之一 xdg-mime
例如 xdg-mime query filetype <file>
如果你有百胜,
yum install xdg-utils.noarch
在Subrip(字幕)文件上xdg-mime和文件的示例比较
$ xdg-mime query filetype subtitles.srt
application/x-subrip
$ file --mime-type subtitles.srt
subtitles.srt: text/plain
Run Code Online (Sandbox Code Playgroud)
在上面的文件中只显示为纯文本.
文件版本<5:文件-i -b/path/to/file
file version> = 5: file --mime-type -b/path/to/file