Get file's signed URL from amazon s3 using Filesystem Laravel 5.2

后端 未结 4 600
南旧
南旧 2021-01-30 10:55

I\'m looking for a good solution to get the signed url from amazon s3.

I have a version working with it, but not using laravel:



        
4条回答
  •  清酒与你
    2021-01-30 11:32

    In Laravel,

    $s3 = \Storage::disk('s3');
    $client = $s3->getDriver()->getAdapter()->getClient();
    $expiry = "+10 minutes";
    
    $command = $client->getCommand('GetObject', [
        'Bucket' => \Config::get('filesystems.disks.s3.bucket'),
        'Key'    => "file/in/s3/bucket"
    ]);
    
    $request = $client->createPresignedRequest($command, $expiry);
    
    return (string) $request->getUri();
    

    Make sure you have the AWS for flysystem composer package too (version will vary):

    "league/flysystem-aws-s3-v3": "1.0.9"
    

提交回复
热议问题