We can use the
net/http package to find the content type, or mime type, of a file. To do this, we open the file and read the first 512 bytes (as the
DetectContentType() function only uses the first 512 bytes, there’s no point in doing more than needed). This function will then return a mime type, like
image/jpg for instance.