7

Golang 的 http.DetectContentType 有更好的替代实现吗?

 3 years ago
source link: https://www.v2ex.com/t/801390
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

Golang 的 http.DetectContentType 有更好的替代实现吗?

  xlsepiphone · 1 小时 55 分钟前 · 221 次点击

我发现 http.DetectContentType 无法识别出一个 mp4 文件的文件类型。

只会返回application/octet-stream

http.DetectContentTypenet/http 包提供的一个方法,可以用于识别文件的类型。但是目前看来支持并不完善。

在 GitHub 上看到有相关的讨论,但是貌似没有结论。

直接在命令行用 file 命令是没问题的。

# file 命令输出如下
ISO Media, MP4 Base Media v1 [IS0 14496-12:2003]

ps.用过文件扩展名判断不靠谱,所以想通过文件头判断。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK