laravel get image s3 code example
Example 1: store image to s3 laravel
use Illuminate\Support\Facades\Storage;
$image = $request->file('image');
$filePath = 'images/' . $image->getClientOriginalName();
Storage::disk('s3')->put($filePath, file_get_contents($image), 'public');
Example 2: how to get private images in s3 laravel
use Storage;
use Config;
$client = Storage::disk('s3')->getDriver()->getAdapter()->getClient();
$bucket = Config::get('filesystems.disks.s3.bucket');
$command = $client->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => '344772707_360.mp4'
]);
$request = $client->createPresignedRequest($command, '+20 minutes');
echo $presignedUrl = (string)$request->getUri();