Skip to content

Instantly share code, notes, and snippets.

@fhightower
Created December 30, 2017 18:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhightower/79974552bd02a61b361e614f21cf438d to your computer and use it in GitHub Desktop.
Save fhightower/79974552bd02a61b361e614f21cf438d to your computer and use it in GitHub Desktop.
Uploading a tempfile to Amazon S3.
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()
@danielguilhermino
Copy link

Tks, helped me a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment