June 2018
Intermediate to advanced
398 pages
9h
English
Now, we need to make use of the created bucket and upload a file to it. Remember, the file representation inside the bucket is an object. So, boto3 provides some methods that contain the object as a part of it. We will start by using put_object(). This method will upload a file to the created bucket and store it as an object:
import boto3s3_resource = boto3.resource("s3")bucket = s3_resource.Bucket("my_first_bucket")with open('~/test_file.txt', 'rb') as uploaded_data: bucket.put_object(Body=uploaded_data)
In the preceding example, the following applies:
Read now
Unlock full access