Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move all files and folder from one folder to another of S3 bucket in php with some short way?

I have to move all files and folders from one folder or another of S3 bucket in php. I know a way to do the same thing is - 1) get all objects list from the source folder 2) copy all objects into destination folder 3) delete all objects from source folder

Is there any other short way to do the same. If so then please share with me, It would be appreciated, Thanks in advance

like image 677
Neeraj Rathod Avatar asked Oct 06 '16 05:10

Neeraj Rathod


1 Answers

Is there any other short way to do the same

There is no short way to do this.

Here is the reason:

The concept of folders is unique to the console. Amazon S3 uses buckets and objects, but the service does not natively support folders, nor does it provide any API to work with folders.

To help you organize your data, however, the Amazon S3 console supports the concept of folders. [...]

Important

In Amazon S3, you create buckets and store objects. The service does not support any hierarchy that you see in a typical file system.

The console uses the object key names to derive the folder hierarchy. It uses the "/" character in the key name to infer hierarchy

http://docs.aws.amazon.com/AmazonS3/latest/UG/about-using-console.html

"Moving" files to another "folder," in S3, cannot be done, in reality. It can only be emulated, by making copies of each individual object, giving each object a new key name to the new "hierarchy," then deleting the original. S3 does not even support renaming an individual object. Renaming is also accomplished by making a copy with the new name, then removing the original. The console gives the appearance of supporting these operations, but it actually only emulates them, as described above. This is a deliberate part of the design of S3.

like image 183
Michael - sqlbot Avatar answered Oct 06 '22 03:10

Michael - sqlbot