dimanche 18 août 2019

How to prepare a very big file for user to download with Laravel?

Here is what I want to do :

  1. User purchases a big file (1GB)
  2. Download link is created with laravel's Signed URLs (link is valid for one day)
  3. User can download the file without seeing the actual URL

Here is the working code:

if (!request()->hasValidSignature()) {
            abort(404);
        }

$file = ProductFile::findOrFail($id);
return response()->download($file->path);

But the problem is it takes up all the server's RAM. Even my website does not load while downloading.

I searched around and I think there are two ways:

one: chunking the file and using response:stream(). I tried this, it's working but the download is not Resumable. How to make it resumable? I know I should use Accept-Ranges header But How to do it in laravel?

two: putting the file in a static download host and hide the actual URL. How?

Thank you very much



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/33KsFPw
via IFTTT

Aucun commentaire:

Enregistrer un commentaire