vendredi 22 juin 2018

What is the most fast way to show "secure" images with Laravel and Amazon s3?

In my Laravel application I have a gallery for logged-in users with Amazon S3.

Now I download EVERY thumbnail and image in this way:

public function download($file_url){ // is safe, but slow...
    $mime = \Storage::disk('s3')->getDriver()->getMimetype($file_url);
    $size = \Storage::disk('s3')->getDriver()->getSize($file_url);

     $response =  [
         'Content-Type' => $mime,
         'Content-Length' => $size,
         'Content-Description' => 'File Transfer',
         'Content-Disposition' => "attachment; filename={$file_name}",
         'Content-Transfer-Encoding' => 'binary',
    ];

    return \Response::make(\Storage::disk('s3')->get($file_url), 200, $response);
}

This is safe (because I have a router with middleware('auth'), but is very server-intensive and slow.

Is it possible to download a file directly from Amazon:

  • only for (in my Laravel)-loggedin users (mayby with a temporery download link)?
  • OR only with a secure unique link?


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire