Uploading Files and Images to an Amazon S3 Bucket using Python
As the world grows there are numbers of data generated by many tiny and large companies and to handle these data they need a place where they can arrange/store all data. For any company, it requires a place to store its data and access at any time from anywhere in this world. The place where they store their images/files is called the server. Here we are going to use the AWS web server, AWS provides wonderful services to store numbers of images/files.
Requirements:
1: AWS ACCOUNT: If you are new click here to create an account and log in.
2: IAM Account: After creating AWS Account click here to create an Identity Access Management (IAM) User, which provides an ACCESS_KEY and SECRET_KEY:
To generate access_key and secret_key Click on Users and ADD User-> provide the User name and check on Programmatic access(Access type) -> to set permission select Attach existing policies directly (and search amazons3fullaccess, amazons3readonlyaccess, administration access and check on it) -> click on next: Tags->next: Review -> create user -> and download the download.csv file(It’ll contain your ACCESS_KEY, SECRET_KEY)
3: S3_BUCKET: After creating IAM User you need an S3_Bucket where you store your images/files:
To generate s3_Bucket click here and click on create Bucket -> Enter your Bucket name and select Your Region left remaining as same and click on Create Bucket
Open your Bucket goto Permission-> Bucket Policies-> and write these code and save it:
4: For python need to install boto3 libraries
Start Coding: Now import your AWS access and secret key
Make a connection with AWS S3_Bucket
Now Upload your file before it defines your file type (mimetype = ‘image/jpeg’) after that you upload your file using put_object() and make Access Control Lists(ACL) as public to access it:
Get URL: and last but not least to print URL of the file uploaded on AWS S3_BUCKET
Thanks, buddy for visiting here and giving your precious time with me.
You can get this code from GitHub