Everything with my code works. The only pitfall I am currently facing is that I cannot specify the folder within the S3 bucket that I would like to place my file in. Here is what I have:
s3.meta.client.upload_file('/tmp/'+filename, '<bucket-name>', filename)
I have tried both:
s3.meta.client.upload_file('/tmp/'+filename, '<bucket-name>/folder/', filename)
and:
s3.meta.client.upload_file('/tmp/'+filename, '<bucket-name>', '/folder/'+filename)
if anyone has any tips on how to direct this to a specific folder (if this is possible) please let me know!
To upload folders and files to an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.
s3 has no append functionality. You need to read the file from s3, append the data in your code, then upload the complete file to the same key in s3.
You do not need to pass the Key value as an absolute path. The following should work:
upload_file('/tmp/' + filename, '<bucket-name>', 'folder/{}'.format(filename))
I figured out my problem. I had the right idea with the /folder/
option in the key parameter area, however, I did not need the first /
Thank you all! This is essentially the same idea as hjpotter92's suggestion above.
s3.upload_file(file_path,bucket_name, '%s/%s' % (bucket_folder,dest_file_name))
You can use put_object
in the place of upload_file
:
file = open(r"/tmp/" + filename)
response = s3.meta.client.Bucket('<bucket-name>').put_object(Key='folder/{}'.format(filename), Body=file)
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