I'm implementing Boto3 to upload files to S3, and all works fine. The process that I'm doing is the following:
I get base64 image from FileReader Javascript object. Then I send the base64 by ajax to the server, I decode the base64 image and I generate a random name to rename the key
argument
data = json.loads(message['text'])
dec = base64.b64decode(data['image'])
s3 = boto3.resource('s3')
s3.Bucket('bucket_name').put_object(Key='random_generated_name.png', Body=dec,ContentType='image/png',ACL='public-read')
This works fine but respect to performance, is there a better way to improve it?
I used this and I believe its more effective and pythonic.
import boto3
s3 = boto3.client('s3')
bucket = 'your-bucket-name'
file_name = 'location-of-your-file'
key_name = 'name-of-file-in-s3'
s3.upload_file(file_name, bucket, key_name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With