cbil360
487
4
Laravel

Uploading a local directory to Amazon S3 recursively

Posted 3 years ago by cbil360

I have to push a local user directory to S3 on the initial upload of files to S3.Locally I have a heirarachy

     | -UserDirectory
     |-----album1
     |      |-album1 files
     |-----album2
            |-album2 files

I want to replicate the same structure on S3.I went throught the FileSystem and I also used it for working on files on local server. It has functions for copying and moving objects to S3. http://laravel.com/docs/5.1/filesystem#storing-files

But this implies to single file or object.What is the best way to use it to upload the directory along with subdirectories and files uisng filesystem?
Do I need to get a list of the local directory and then iterate over them to upload one by one?
For Example:

         $files = Storage::allFiles($directory);
         foreach($files as $object)
     {
    Storage::disk('s3')->copy('$object','S3/bucket/path')   
     }

Is this a good solution or I can improve it in some other way?Suggestions and corrections are welcome.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.