I am converting gif images into jpgs using PIL library and uploading them to s3. I get this error:
ValueError: Fileobj must implement read
here is part of code that reads the image and convert to jpgs:
im = Image.open(url)
i = 0
mypalette = im.getpalette()
try:
while 1:
im.putpalette(mypalette)
new_im = Image.new("RGBA", im.size)
new_im.paste(im)
key = 'img'+str(i)+'.jpg'
in_mem_file = io.BytesIO()
new_im.save(in_mem_file, "JPEG")
s3.upload_fileobj(in_mem_file.getvalue(), bucket, key)
i += 1
im.seek(im.tell() + 1)
except EOFError:
pass
I use io.BytesIO to get read the bytes however I still get the same error. if I remove getvalue from in_mem_file empty images are saved in the bucket.
with BytesIO() as in_mem_file:
image.save(in_mem_file, format=image.format)
in_mem_file.seek(0)
s3client.upload_fileobj(in_mem_file, BUCKET, path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With