在S3 bucket (ruby)中复制文件



我正在使用gem aws-sdk-ruby,我想将文件/images/image_a.png复制到/profile.png

我该怎么做呢?

从文档中提取,您将不得不使用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)

使用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"))

相关内容

  • 没有找到相关文章

最新更新