9

我正在使用 gem aws-sdk-ruby 并且我想将文件 /images/image_a.png 复制到 /profile.png 都位于同一个存储桶中。

我怎样才能做到这一点?

4

2 回答 2

9

从文档中提取,您必须使用copy_to. 例如:

s3 = AWS::S3.new

# Upload a file and set server-side encryption.
bucket1 = s3.buckets[source_bucket]
bucket2 = s3.buckets[target_bucket]
obj1 = bucket1.objects[source_key]
obj2 = bucket2.objects[target_key]

obj1.copy_to(obj2)
于 2013-04-21T14:03:08.300 回答
3

to do this with aws-sdk-v2 you can do the following:

bucket = Aws::S3::Bucket.new('my_aws_bucket')
bucket.object("new_photo_uploads/logos/my_new_copied_photo.png")
aws_response = object.copy_from(bucket.object("my_original_photo.png"))
于 2016-01-15T04:16:40.710 回答