user3882060
user3882060

Reputation: 51

How to upload file to exact location on S3 bucket using Boto

I have a bucket by the path like s3://hello/sir. i want to upload file inside sir folder.I tried many things so far not able to push the file on s3. I am able to upload on hello path. This is what I tried s3 = boto3.resource('s3')

s3.Bucket('hello').upload_file('my.txt', 'sir/my.txt')

Upvotes: 0

Views: 989

Answers (1)

CK__
CK__

Reputation: 1311

This is what I tried and worked for me:

import boto3


client = boto3.client('s3')
client.upload_file('/Users/data/local-file.txt', 'temp-data-user-bucket',
                   'hello/sir/sample.txt')

After running above code I was able to see file in /hello/sir/ path. You can refer the below screenshot:

enter image description here

I am renaming the local file local-file.txt --> sample.txt while using the API but you can keep the same name this is completely optional.

You can refer the upload_file() API here.

Upvotes: 2

Related Questions