go后端如何支持HEIC/HEIF图片?

发布于 2025-01-19 02:42:19 字数 307 浏览 3 评论 0原文

我很新来。我有一些图像上传代码,我正在尝试上传*。HEIC由iPhone产生的图像。我的代码正在执行以下操作:

contentType := http.DetectContentType(fileBytes)

detectContentType不知道如何检测HEIC的内容类型,这导致默认application/optrappy/octet-stream content类型。有没有办法增加对GO的新内容类型的支持?

I am pretty new to Go. I have some image upload code and I am trying to upload a *.heic image that is produced by iPhones. My code is doing the following:

contentType := http.DetectContentType(fileBytes)

DetectContentType does not know how to detect content type for HEIC, which results in default application/octet-stream content type. Is there a way to add support for new content types that Go does not know how to handle yet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无悔心 2025-01-26 02:42:19

http.detectcontenttype函数旨在匹配媒体类型嗅探规范。因此,这是不可扩展的。

但是,您不需要扩展它:没有什么可以阻止您编写自己检测HEIC的功能,并且如果数据与HEIC不匹配,则可以回到http.detectContentType

The http.DetectContentType function is designed to match the Media Type Sniffing specification. As such, it's not extensible.

However, you don't need to extend it: there's nothing preventing you from writing your own function that detects HEIC, and that falls back to http.DetectContentType if the data does not match HEIC.

猛虎独行 2025-01-26 02:42:19

该库比 http.DetectContentType 中的构建具有更广泛的支持:

https:// /github.com/gabriel-vasile/mimetype

它会正确识别 HEIC 图像,尽管据我所知,Go 没有对 HEIC 的“原生”支持(有库,但它们只是包装器) C绑定/libde265 等)。

This library has much wider support than the build in http.DetectContentType:

https://github.com/gabriel-vasile/mimetype

It'll correctly recognise HEIC images, although there is no "native" Go support for HEIC that I'm aware of (there are libraries, but they are just wrappers around C bindings/libde265 etc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文