有没有办法在 Linux bash 脚本中找出文件的 MIME 类型(或者称为“Content-Type”?)?
我需要它的原因是因为 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-TYPE。
$ curl -F "fileupload=@/1.png;type=image/png" http://www.imageshack.us/upload_api.php
原文由 Mint 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用
file
。例子: