conn = tinys3.Connection(S3_ACCESS_KEY,S3_SECRET_KEY)
f = open('sample.zip','rb')
conn.upload('sample.zip',f,bucketname)
我可以通过上面的代码将文件上传到我的存储桶(测试),但我想将其直接上传到test / images / example。我愿意转向boto,但我似乎无法在我的环境中导入boto.s3。
我查看了How to upload a file to directory in S3 bucket using boto,但没有一个tinys3示例显示这一点。
答案 0 :(得分:3)
import boto3
client = boto3.client('s3', region_name='ap-southeast-2')
client.upload_file('/tmp/foo.txt', 'my-bucket', 'test/images/example/foo.txt')
答案 1 :(得分:0)
以下内容对我有用
from boto3.s3.transfer import S3Transfer
from boto3 import client
client_obj = client('s3',
aws_access_key_id='my_aws_access_key_id',
aws_secret_access_key='my_aws_secret_access_key')
transfer = S3Transfer(client_obj)
transfer.upload_file(src_file,
'my_s3_bucket_name',
dst_file,
extra_args={'ContentType': "application/zip"})