I am calling an API that returns a iterator object containing image data. I'd like to iterate over them and upload to s3. I could either open them into .png or .jpeg before or after dumping / uploading them to s3.
import boto3
# Download / open photo
img_obj = gmaps.places_photo(ph, max_width = 500, max_height = 400)
print(img_obj)
<generator object Response.iter_content.<locals>.generate at 0x7ffa2dsa7820>
s3 = boto3.client('s3')
with open('output_image_{}.png'.format(c), 'w') as data:
for chunk in img_obj:
s3.upload_fileobj(data,'mybucket','img/{}'.format(chunk))
Error:
Input <_io.BufferedWriter name='output_image_1.png'> of type: <class '_io.BufferedWriter'> is not supported.
On local machine, I am able to write the file:
with open("output_image_{}.png".format(c), "w") as fp:
for chunk in img_obj:
fp.write(chunk)
I'd like to directly save the img_obj on AWS S3.
