title: Save image data from a iterator object to AWS S3 in python
body: <p>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 <code>.png</code> or <code>.jpeg</code> before or after dumping / uploading them to s3.</p>
  <pre><code>import boto3
  
  # Download / open photo
  img_obj = gmaps.places_photo(ph, max_width = 500, max_height = 400)
              
  print(img_obj)
  
  &lt;generator object Response.iter_content.&lt;locals&gt;.generate at 0x7ffa2dsa7820&gt;
              
  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))
  </code></pre>
  <p>Error:</p>
  <pre><code>Input &lt;_io.BufferedWriter name='output_image_1.png'&gt; of type: &lt;class '_io.BufferedWriter'&gt; is not supported.
  </code></pre>
  <p>On local machine, I am able to write the file:</p>
  <pre><code>with open(&quot;output_image_{}.png&quot;.format(c), &quot;w&quot;) as fp:
      for chunk in img_obj:
         fp.write(chunk)
  </code></pre>
  <p>I'd like to directly save the <code>img_obj</code> on AWS S3.</p>