Upload Files/Images on 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.

AWS s3ucket
files/images stores on AWS s3-BUCKET

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:

IAM USER

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:

Enter Your own bucket name at (YOUR_BUCKET_NAME)

4: For python need to install boto3 libraries

boto3 installation code

Start Coding: Now import your AWS access and secret key

AWS ACCESS_KEY, SECRET_KEY, Bucket Name

Make a connection with AWS S3_Bucket

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:

upload your file with providing your FILENAME and FILE

Get URL: and last but not least to print URL of the file uploaded on AWS S3_BUCKET

URL for Bucket file

Thanks, buddy for visiting here and giving your precious time with me.
You can get this code from GitHub

Python Developer