1

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)

and Already used php artisan storage:link

Milad
  • 719
  • 1
  • 10
  • 28
  • 1
    php artisan storage:link and then you return a link like: yoursite/storage/.../yourfile.zip Check the manual – Indra May 17 '18 at 12:46
  • @Indra I already use this method and just returns The "[public/storage] directory has been linked." – Milad May 17 '18 at 12:49

1 Answers1

0

I do not know it's bug or lake of my knowledge about storage in laravel framework :

when you saving the file by storage is going return the path of a file so I saving that path in my database when I giving this path to the code above return that error so out nowhere I decide to send just filename without a path and simply code works.

I hope this answer helps someone!

Milad
  • 719
  • 1
  • 10
  • 28