October 2019
Intermediate to advanced
426 pages
10h 8m
English
Let's create a Python class named StorageService as shown in the following, in the storage_service.py file located in the chalicelib directory:
import boto3class StorageService: def __init__(self, storage_location): self.client = boto3.client('s3') self.bucket_name = storage_location def get_storage_location(self): return self.bucket_name def upload_file(self, file_bytes, file_name): self.client.put_object(Bucket = self.bucket_name, Body = file_bytes, Key = file_name, ACL = 'public-read') return {'fileId': file_name, 'fileUrl': "http://" + self.bucket_name + ".s3.amazonaws.com/" + file_name}
In the preceding code, the following applies:
Read now
Unlock full access