Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I am trying to get a simple image upload app working on Heroku using Flask. I'm following the tutorial here:

However, I want to use S3 to store the file instead of a temporary directory, since Heroku does not let you write to disk. I cannot find any examples of how to do this specifically for Heroku and Flask.

1 Answer

0 votes
by (44.4k points)

For instance, from the linked page:

def upload_file():

    if request.method == 'POST':

        file = request.files['file']

        if file and allowed_file(file.filename):

            filename = secure_filename(file.filename)

            s3 = boto.connect_s3()

            bucket = s3.create_bucket('my_bucket')

            key = bucket.new_key(filename)

            key.set_contents_from_file(file, headers=None, replace=True, cb=None, num_cb=10, policy=None, md5=None) 

            return 'successful upload'

    return ..

You can use the queuing mechanism is provided by Heroku if you want to upload S3 asynchronously.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories