go后端如何支持HEIC/HEIF图片?
我很新来。我有一些图像上传代码,我正在尝试上传*。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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.该库比
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).