laravelamazon-s3laravel-5.3flysystem

How can I transfer a file from one bucket to another using flysystem?


I have objects in one bucket that I occasionally need to transfer to a second bucket in Amazon S3. I'm using Laravel 5.3 with Flysystem to manage those buckets.

One solution is to download the images to my server and then upload it to the other bucket but this seems like a waste of time/bandwidth since the file exists in S3 and is getting moved within S3. Can this be done within Flysystem or will I need to directly use Amazon's API?


Solution

  • You can use the FilesystemAdapter move function to move a file:

    $disk = Storage::disk('s3');
    if (!$disk->move('bucketOne/testFile.jpg', 'bucketTwo/testFile.jpg')) {
       throw new \Exception('File could not be moved.');
    }