title: How to upload a file to s3 from a file upload form after modifying it with PIL?
body: <p>Here is the code stuff: </p>
  
  <pre><code>app.config['DEBUG']= True
  
  
  if request.method == 'POST' and request.form['file_submit']:
          print request.form
          print request.files['image']
          if request.files['image']:
              print 'foshhh'
              image_file = request.files['image']
              img = PIL.Image.open(image_file.stream)
              print img
              if request.form['make_transparent']:
                  threshold=100
                  print 'changin sizesd'
                  dist=5
                  # np.asarray(img) is read only. Wrap it in np.array to make it modifiable.
                  arr=np.array(np.asarray(img))
                  r,g,b,a=np.rollaxis(arr,axis=-1)
                  mask=((r&gt;threshold)
                      &amp; (g&gt;threshold)
                      &amp; (b&gt;threshold)
                      &amp; (np.abs(r-g)&lt;dist)
                      &amp; (np.abs(r-b)&lt;dist)
                      &amp; (np.abs(g-b)&lt;dist)
                      )
                  arr[mask,3]=0
                  img=Image.fromarray(arr,mode='RGBA')
              if request.form['change_size']:
                  img = Image.open('out.png')
                  img.thumbnail(size,Image.ANTIALIAS)
                  img.save('out.png',"PNG")
  
              img.save('out.png',"PNG")
              print os.path.getsize("out.png")   #from answer
              assert os.path.isfile("out.png")   #from answer
              conn = S3Connection(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)
              b = conn.get_bucket('snappie.watermarks')
              k = Key(b)
              k.key = "test.png"
              k.set_metadata('Content-Type', 'image/png')
              k.set_contents_from_filename("out.png")
              print "got file"
              return redirect("https://s3.amazonaws.com/snappie.watermarks/"+filename)
          else:
              print 'please upload a file to submit the form!'
  </code></pre>
  
  <p>and here is the html form :</p>
  
  <pre><code>   &lt;form method="POST" enctype="multipart/form-data" name="file_submit"&gt;
              &lt;label&gt;Choose png here.&lt;input type="file" name="image"&gt;&lt;/label&gt;
              &lt;input type="hidden" name="file_submit" value="yes"&gt;
              Change size?&lt;input type="checkbox" name="change_size" value="yes"/&gt;
              Make Background Transparent?&lt;input type="checkbox" name="make_transparent" value="yes"\&gt;&lt;br&gt;&lt;br&gt;
              &lt;input type="submit" value="submit"&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>part of the problem is that It doesn't really give me an error log. You can see that the idea is that there are 2 checkboxes which can modify the image file. If the first one is checked, its "made transparent" and if the second one is checked, it changes the size. </p>
  
  <p>I think I am having issue with the type of the image object when it gets converted and modified, especially when it gets passed into this object:             <code>k.set_contents_from_filename("out.png")</code></p>
  
  <p>Any help here? This is the only output the server logs give me: </p>
  
  <pre><code>GET
  127.0.0.1 - - [18/Jan/2015 15:42:26] "GET / HTTP/1.1" 200 -
  POST
  ImmutableMultiDict([('file_submit', u'yes')])
  &lt;FileStorage: u'birnam_wood.jpg' ('image/jpeg')&gt;
  foshhh
  &lt;PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=100x100 at 0x7FDDF4CA6C68&gt;
  127.0.0.1 - - [18/Jan/2015 15:42:32] "POST / HTTP/1.1" 400 -
  </code></pre>