在boto 3中,“ Key.set_contents_from_”方法被替换为
Object.put()
Client.put_object()
例如:
import boto3some_binary_data = b'Here we have some data'more_binary_data = b'Here we have some more data'# Method 1: Object.put()s3 = boto3.resource('s3')object = s3.Object('my_bucket_name', 'my/key/including/filename.txt')object.put(Body=some_binary_data)# Method 2: Client.put_object()client = boto3.client('s3')client.put_object(Body=more_binary_data, Bucket='my_bucket_name', Key='my/key/including/anotherfilename.txt')
另外,二进制数据可以来自读取文件,如官方文档中比较boto 2和boto
3所述:
储存资料从文件,流或字符串存储数据很容易:
# Boto 2.xfrom boto.s3.key import Keykey = Key('hello.txt')key.set_contents_from_file('/tmp/hello.txt')# Boto 3s3.Object('mybucket', 'hello.txt').put(Body=open('/tmp/hello.txt',‘rb’))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)