jeudi 17 mai 2018

Laravel downloading large file end up not found

I am developing an e-commerce website for selling files and all of the download files or more than 500Mb. so for more protection, I store all files inside storage folder and create disk like this

'academy' => [
        'driver' => 'local',
        'root' => storage_path('app/academy'),
    ],

so as I mantion all files sizes are more than 500Mb so I can't simply using Responce::download (after two download === server shutdown memeory fill up)

so I search in StackOverflow and find this answers #1 and #2 so I use this code for downloading a file :

$fs = Storage::disk('academy')->getDriver();

$fileName = $file; //-> path to file

$metaData = $fs->getMetadata($fileName);
$stream = $fs->readStream($fileName);

if (ob_get_level()) ob_end_clean();

return response()->stream(
    function () use ($stream) {
        while(ob_end_flush());
        fpassthru($stream);
    },
    200,
    [
        'Content-Type' => $metaData['type'],
        'Content-disposition' => 'attachment; filename="' . $metaData['path'] . '"',
    ]);

and after running getting this error

"File not found at path: D:/laragon/www/store/storage/app/academy/7FrggloHEjjc72rVJO1jPdF10nJL57MBMBvfwpYE.zip"

on this file

D:\laragon\www\store\vendor\league\flysystem\src\Filesystem.php Line 388

public function assertPresent($path)
{
    if ($this->config->get('disable_asserts', false) === false && ! $this->has($path)) {
        throw new FileNotFoundException($path);
    }
}

The funny thing about this error is the path that returns if put in windows explorer it open the zip file (Path is correct)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire