Skip to content

Instantly share code, notes, and snippets.

@mhemrg
Forked from ukautz/s3-in-laravel.php
Last active April 4, 2021 14:55
Show Gist options
  • Save mhemrg/76a0454ccc07f700a035f039834e29b0 to your computer and use it in GitHub Desktop.
Save mhemrg/76a0454ccc07f700a035f039834e29b0 to your computer and use it in GitHub Desktop.
Using S3 client directly in Laravel | Copy file between buckets
<?php
/** @var \Illuminate\Filesystem\FilesystemAdapter $fs */
$fs = \Storage::disk('liara');
/** @var \League\Flysystem\Filesystem $driver */
$driver = $fs->getDriver();
/** @var \League\Flysystem\AwsS3v3\AwsS3Adapter $adapter */
$adapter = $driver->getAdapter();
/** @var \Aws\S3\S3Client $client */
$client = $adapter->getClient();
try {
$client->copy(
'bucket1',
'current_name',
'bucket2',
'new_name',
'private',
$this->options
);
} catch (\Aws\S3\Exception\S3Exception $e) {
// handle exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment