Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy an entire "folder" to another path using S3 with sdk?

Tags:

ruby

amazon-s3

When I do for a single file it works:

    aws_s3 = AWS::S3.new(S3_CONFIG)
    bucket = aws_s3.buckets[S3_CONFIG["bucket"]]

    object = bucket.objects["user/1/photos/image_1.jpg"]
    new_object = bucket.objects["users/1/photos/image_1.jpg"]
    object.copy_to new_object, {:acl => :public_read}

But I want to move the entire "/photos" folder throws No Such Key. Probably the s3 keys are only the full path for each file. How to do that?

    aws_s3 = AWS::S3.new(S3_CONFIG)
    bucket = aws_s3.buckets[S3_CONFIG["bucket"]]

    object = bucket.objects["user/1/photos"]
    new_object = bucket.objects["users/1/photos"]
    object.copy_to new_object, {:acl => :public_read}

Thanks!

like image 570
Luccas Avatar asked Dec 14 '12 18:12

Luccas


1 Answers

Did it:

bucket.objects.with_prefix("user/1/photos").each do |object|
   ...
end
like image 97
Luccas Avatar answered Oct 18 '22 19:10

Luccas