title: fileobj must implement read
body: <p>On Elastic Beanstalk I'm using the following Python code to handle a POST request and upload a file to a S3 bucket. However, I get the following error:</p>
  
  <blockquote>
    <p>fileobj must implement read</p>
  </blockquote>
  
  <p>after reading Flask's FileStorage documentation, I've tried to substitute f with f.stream, but then I've got:</p>
  
  <blockquote>
    <p>expected string or buffer</p>
  </blockquote>
  
  <p>I'm using Werkzeug 0.10.1. How can I fix this?</p>
  
  <pre><code>from flask import Flask, render_template, request
  from werkzeug.utils import secure_filename
  from s3upload.helpers import *
  
  application = Flask(__name__)
  application.config.from_object('s3upload.config')
  
  ALLOWED_EXTENSIONS = ('pdf','p')
  
  
  def allowed_file(filename):
      if filename.rsplit('.')[1].lower() in ALLOWED_EXTENSIONS:
          return True
  
  
  def upload_file_to_s3(f, bucket_name, acl='public-read'):
      try:
          s3.upload_fileobj(f, bucket_name, f.filename, ExtraArgs={
                  "ACL": acl,
                  "ContentType": f.content_type
              })
      except Exception as e:
          return "Something bad happened while uploading {} in {}: {} {}".format(f.filename, bucket_name, e)
      return '{}{}'.format(application.config['S3_LOCATION'], f.filename)
  
  
  @application.route('/', methods=['POST','GET'])
  def upload_file():
      if request.method == 'POST':
          if 'file' not in request.files:
              return "No file key in request.files"
  
          f = request.files['file']
  
          if f.filename == '':
              return "Please select a file."
  
          if allowed_file(f.filename):
              f.filename = secure_filename(f.filename)
              out = upload_file_to_s3(f, application.config['S3_BUCKET'])
              return str(out)
          else:
              return "File type not allowed."
      return render_template('index.html')
  
  
  if __name__ == '__main__':
      application.run()
  </code></pre>