[Django]-How do I upload Pillow processed image to S3 on Django?

9👍

✅

The Image.save() method doesn’t return an image, it saves it to disk (or buffer) and returns None. That is why boto is complaining about NoneType parameters.

You want to save the data to some temporary buffer and then pass that off to boto. For example:

buffer = io.BytesIO()
im.save(buffer, "JPEG")
buffer.seek(0) # rewind pointer back to start
s3.put_object(
    Bucket=settings.AWS_S3_DEV_IMG_BUCKET,
    Key=img_name,
    Body=buffer,
    ContentType='image/jpeg',
)

Leave a comment