0
votes

I am triying to upload a document with the Storage disk method. I can upload him in this the /storage/app/public .But now I want to allow the user to dowload into his computer. So that is my App Url in the .env

APP_URL=http://backend-debug.localhost

In the filesystems.php I create a new link "import"

'import' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage/app/public',
        'visibility' => 'public',
    ],

finally I return him with

$response['url'] = Storage::disk('import')->url('export-error/'.$filename);
    Log::info('url = '.$response['url'] );
    return $response;

The log gives this information.

url = http://backend-debug.localhost/storage/app/public/export-error/error_file.csv

I am using Laravel 5.6
I can't dowload my Document into my pc
Any idea ?
Thank you

1
What is not working?Chin Leung
Replace env(APP_URL) with public_path()AntonyMN
Does it give 404 error?Vaibhavraj Roham
I should be able to download to my computer but I just have a redirect on a blank page.ThibaudkhanFalse
Does that file exists on storage/app/public/export-error/error_file.csv?Vaibhavraj Roham

1 Answers

0
votes

By looking to http://localhost:4200/mnt/data/backend/public/storage/app/public/export-error/error_file.csv URL it seems that your import filesystem connection is correct.

Here, Laravel tries to find the storage directory inside the public directory which is correct. To ensure this, you need to symlink the storage directory inside a public directory. Laravel provides a command to create one if not exist.

To create symlink, run following command.

php artisan storage:link

This command will create a symlink of storage directory in public directory. If you are using windows then simply create a shortcut of storage directory inside public directory.

For more information visit, https://laravel.com/docs/5.8/filesystem#the-public-disk

Thanks.