简体   繁体   English

在S3中使用ruby复制_to

[英]copy_to in s3 using ruby

Am trying to copy an image from bucket to another bucket in s3. 我正在尝试将图像从存储桶复制到s3中的另一个存储桶。

     AWS.config(
          :access_key_id => 'Bucket one key', 
          :secret_access_key => 'bucket one secret key'
     )
     s3 = AWS::S3.new

     bucket1 = s3.buckets["Bucket_one"]
     bucket2 = s3.buckets["Bucket_two"]
     obj1 = bucket1.objects["source_key"]
     obj2 = bucket2.objects["destination_key"]

     obj1.copy_to(obj2)

Can you guide me as to how to retrieve the source key of a file already uploaded in S3? 您能指导我如何检索S3中已经上传的文件的源密钥吗? I have the destination_key,bucket_one and bucket_two. 我有destination_key,bucket_one和bucket_two。

Image on S3 is not a single file but a number of files names of which starts from the name of your image. S3上的映像不是单个文件,而是多个文件名,这些文件名始于映像的名称。 Thus you need to know the name of your image. 因此,您需要知道图像的名称。 Once you get it, the could should look like: 一旦获得它,容器应该看起来像:

bucket1 = s3.buckets["Bucket_one"]
bucket2 = s3.buckets["Bucket_two"]
bucket1.objects.with_prefix(image_name).each do |source_object|
  source_object.copy_to(bucket2.objects[source_object.key])
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM