我正在使用gem aws-sdk-ruby,我想将文件/images/image_a.png复制到/profile.png 全部都在同一个桶里。
我该怎么做?
答案 0 :(得分:6)
从documentation中提取,您必须使用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)
答案 1 :(得分:3)
使用aws-sdk-v2执行此操作,您可以执行以下操作:
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"))