Uploading files to AWS S3 with Flask

Aniket Wattamwar
AWS Pocket
Published in
3 min readJul 13, 2020

--

In this article you will learn how to upload files to your S3 bucket using Flask from your website.

Note: You must have an account on aws to access the S3 service.

We will be having

  • .py file with the flask code
  • .html file to choose the file from the website

In the html file you need to put the following code:

<form action="/upload" method="post" enctype="multipart/form-data">
<p class="card-text">Choose a file to upload it to AWS S3</p>
<input type="file" name="file" value="file">
<hr>
<input type="submit" name="upload" value="Upload" class="btn btn-success">
</form>
{{msg}}

You will find two inputs with type file and submit respectively. The input with type file will allow you to select the a file/image from your computer. The input with type submit will allow to upload it.

When the user clicks on the submit type button form action = /upload function is triggered. This is where the flask part comes into picture.

Before we get into that, lets connect out aws account with our flask application. To do so look at the following code:

import boto3s3 = boto3.client('s3'…

--

--