Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS::S3 rename a folder

Tags:

ruby

amazon-s3

I see there is an AWS::S3::S3Object.rename but I can't do it with folders:

AWS::S3::Base.establish_connection!(
 :access_key_id     => APP_CONFIG[:s3_access_key_id],
 :secret_access_key => APP_CONFIG[:s3_secret_access_key]
)
AWS::S3::S3Object.rename(
 "assets/old_name_folder",
 "assets/new_name_folder",
 APP_CONFIG[:s3_bucket]
)

The old_name_folder contains files and folders and I want the renaming to respect this.

I'm obtaining: AWS::S3::NoSuchKey (The specified key does not exist.)

I don't know if I'm doing something wrong or it is just not possible to rename s3 folders.

like image 433
fguillen Avatar asked Mar 30 '11 16:03

fguillen


People also ask

Can I rename a folder in S3?

All you have to do is to select a file or folder you want to rename and click on the “Rename” button on the toolbar.

Can I rename file in S3?

There is no direct method to rename the file in s3. what do you have to do is copy the existing file with new name (Just set the target key) and delete the old one.

How do I change the filename in a S3 bucket?

There is no direct method to rename a file or folder in Amazon S3. But we can perform a little bit edge around. What you have to do is to create a new “folder” in S3 and then move all of the files from that “folder” to the new “folder.” Once all files are moved, we can remove the source “folder.”


1 Answers

The documentation for AWS::S3 explains this pretty well. When storing files on s3, there are no such things as folders. There is a bucket (your APP_CONFIG[:s3_bucket] presumably), and there are objects. That is it. There are no folders. One of your objects might be named /files/public/system/whatever/derp.jpg - but there are no folders there, only an object with a name that looks like a path, and then the value of the object (the actual file residing at that location).

So to answer your question, you cannot rename folders because there is no such thing on s3. You have to rename individual objects.

like image 96
Brett Bender Avatar answered Oct 11 '22 11:10

Brett Bender