2

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?

Andrew Bezzub
  • 15,744
  • 7
  • 51
  • 73

1 Answers1

1

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.

jch
  • 5,382
  • 22
  • 41