title: Amazon S3 File Uploading issue using "BOTO" in my flask application -Python
body: <p>In my flask application, I am using a function to upload file to Amazon s3, using Boto.</p>
  
  <p>Its working fine most of the cases, but some times its uploading files as zero byte file with no extension.</p>
  
  <p>Why its failing sometimes,</p>
  
  <p>I am validating user image file in form.</p>
  
  <p><code>FileField('Your photo',validators=[FileAllowed(['jpg', 'png'], 'Images only!')])</code></p>
  
  <p>My image upload function.</p>
  
  <pre><code>def upload_image_to_s3(image_from_form):
  
  
      #upload  pic to amazon
      source_file_name_photo = secure_filename(image_from_form.filename)
      source_extension = os.path.splitext(source_file_name_photo)[1]
      destination_file_name_photo = uuid4().hex + source_extension
  
  
      s3_file_name = destination_file_name_photo
  
      # Connect to S3 and upload file.
  
      conn = boto.connect_s3('ASJHjgjkhSDJJHKJKLSDH','GKLJHASDJGFAKSJDGJHASDKJKJHbbvhjcKJHSD')
      b = conn.get_bucket('mybucket')
  
      # Connect to S3 and upload file.
  
      sml = b.new_key("/".join(["myfolder",destination_file_name_photo]))
      sml.set_contents_from_string(image_from_form.read())
      acl='public-read'
      sml.set_acl(acl)
  
      return s3_file_name
  </code></pre>