Added Content-Type to S3 object on variant creation
This commit is contained in:
@@ -99,6 +99,8 @@ class Image(models.Model):
|
|||||||
available=True,
|
available=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
content_type = "image/jpeg"
|
||||||
|
|
||||||
with PILImage.open(original_image) as im:
|
with PILImage.open(original_image) as im:
|
||||||
ImageOps.exif_transpose(im, in_place=True)
|
ImageOps.exif_transpose(im, in_place=True)
|
||||||
im = im.filter(ImageFilter.GaussianBlur(gaussian_blur))
|
im = im.filter(ImageFilter.GaussianBlur(gaussian_blur))
|
||||||
@@ -110,6 +112,7 @@ class Image(models.Model):
|
|||||||
try:
|
try:
|
||||||
im.save(resized_image, "PNG")
|
im.save(resized_image, "PNG")
|
||||||
image_variant.file_extension = "png"
|
image_variant.file_extension = "png"
|
||||||
|
content_type = "image/png"
|
||||||
except OSError:
|
except OSError:
|
||||||
im.convert("RGB").save(resized_image, "JPEG")
|
im.convert("RGB").save(resized_image, "JPEG")
|
||||||
else:
|
else:
|
||||||
@@ -120,7 +123,11 @@ class Image(models.Model):
|
|||||||
|
|
||||||
resized_image.seek(0)
|
resized_image.seek(0)
|
||||||
|
|
||||||
bucket.upload_fileobj(resized_image, image_variant.backblaze_filepath)
|
bucket.upload_fileobj(
|
||||||
|
resized_image,
|
||||||
|
image_variant.backblaze_filepath,
|
||||||
|
ExtraArgs={"ContentType": content_type},
|
||||||
|
)
|
||||||
|
|
||||||
image_variant.save()
|
image_variant.save()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user