About JPEG image files
The type is image/jpeg for both extensions; image/jpg is a common typo that is not registered, although browsers display it anyway. Upload validators that check for an exact type should accept the correct name and, if needed, the typo, but not rely on either: check that the file starts with FF D8 FF.
Other types seen for these files:
image/jpg
,
image/pjpeg
. Accept them when reading uploads, but send image/jpeg yourself.
File signature
JPG files start with FF D8 FF. The extension and the type a browser reports for an upload both
come from the file name, so check these bytes on the server before trusting a file.
Serve .jpg with the right Content-Type
Content-Type: image/jpeg
image/jpeg jpg jpeg jpe jfif;
AddType image/jpeg .jpg .jpeg .jpe .jfif
@jpg path *.jpg *.jpeg *.jpe *.jfif
header @jpg Content-Type "image/jpeg"
curl -sI https://example.com/file.jpg | grep -i '^content-type'
# Content-Type: image/jpeg
Set the type in code
res.set('Content-Type', 'image/jpeg');
// Or make the browser download it:
res.attachment('file.jpg');
import mimetypes
mimetypes.add_type('image/jpeg', '.jpg') # if your system doesn't know it
mimetypes.guess_type('file.jpg')[0] # 'image/jpeg'
mime.AddExtensionType(".jpg", "image/jpeg")
w.Header().Set("Content-Type", "image/jpeg")
Accept .jpg uploads
<input type="file" accept=".jpg,.jpeg,.jpe,.jfif,image/jpeg">
The accept attribute only filters the file picker; users can still choose another file. Listing the
extension as well as the type matters, because operating systems don’t always report the type you expect.
Related types
-
.png (
image/png): PNG image -
.webp (
image/webp): WebP image -
.avif (
image/avif): AVIF image -
.heic (
image/heic): HEIC image
More images
.gif , .ico , .bmp , .tiff . Look up any extension or type with the MIME type lookup.
Sources
Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.
Frequently asked questions
What is the MIME type for .jpg files?
image/jpeg. You may also see image/jpg, image/pjpeg, which are older or unofficial; send image/jpeg. The full header is "Content-Type: image/jpeg".
Why does my server send the wrong Content-Type for .jpg?
Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .jpg is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".
How can I check that a file really is JPG?
Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. JPG files start with FF D8 FF. The MIME type lookup on this site reads them for you when you drop a file on it.