Created
December 30, 2017 18:23
-
-
Save fhightower/79974552bd02a61b361e614f21cf438d to your computer and use it in GitHub Desktop.
Uploading a tempfile to Amazon S3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tempfile | |
import boto3 | |
s3 = boto3.client('s3') | |
bucket_name = 'my-bucket' | |
file_key = 'myfile.txt' | |
temp_file = tempfile.TemporaryFile() | |
try: | |
temp_file.write('File content here...') | |
temp_file.seek(0) | |
s3.upload_fileobj(temp_file, bucket_name, file_key) | |
finally: | |
temp_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tks, helped me a lot!