title: upload file using flask to amazon s3
body: <p>This is the code that handles the uploading request:</p>
  
  <pre><code>@app.route('/upload', methods=['POST'])
  def upload():
      if request.method == 'POST':
          test = request
          data_file = request.files.get('file')
          file_name = data_file.filename
          conn = S3Connection(settings.ACCESS_KEY, settings.SECRET_KEY)
          bucket = conn.get_bucket(settings.BUCKET_NAME)
          k = Key(bucket)
          k.key = 'file_test.jpg'
          # k.set_contents_from_file(data_file)
          k.set_contents_from_string(data_file.readlines())
  
          # return jsonify(name=file_name)
          return jsonify(name=file_name)
  </code></pre>
  
  <p>I've tried 3 options:</p>
  
  <pre><code>k.set_contents_from_string(data_file.readlines())
  k.set_contents_from_file(data_file)
  k.set_contents_from_stream(data_file.readlines())
  </code></pre>
  
  <p>So what is the right way to upload files to amazon s3?</p>