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

后端 未结 4 610
南旧
南旧 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:46

    After lot of bugs, at last, I found the solution of accessing private content of s3 bucket using below code:-

    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'  // file name in s3 bucket which you want to access
    ]);
    
    $request = $client->createPresignedRequest($command, '+20 minutes');
    
    // Get the actual presigned-url
    echo $presignedUrl = (string)$request->getUri();
    

提交回复
热议问题