laravel storage embed pdf not found

701 views Asked by At

I want to embed a PDF file into a modal blade view. The disk is not public (because it shouldn't be) and with a logged in user, I get the 404 not found message.

Inside config/filesystems.php I got:

<?php
    'disks' => [
        'custom' => [
            'driver' => 'local',
            'root' => storage_path('app/custom'),
        ],

Inside my blade view I already tested successfully

<iframe src="https://www.inkwelleditorial.com/pdfSample.pdf" width="100%" height="300"></iframe>

However, when I try:

<iframe src="{{ storage_path('app/custom/myFile.pdf')}}" width="100%" height="300"></iframe>

I get

404 NOT FOUND

I have made sure the file does exist:

dd(Storage::disk('custom')->path('myFile.pdf')) => shows absolute path correctly

dd(Storage::disk('custom')->exists('myFile.pdf')) => returns true.

How do I fix this?

1

There are 1 answers

0
gouki On

First,you must know that storage_path() is a private path. if you want show storage file on web, you can see the config file config/filesystems.php

    'links' => [
        public_path('storage') => storage_path('app/public'),
    ],

run this command: php artisan storage:link , then go to public directory,you can see the soft link directory on the public directory.

Then you can use the url on webpage like this <ifram src="/storage/app/custom/xxx.pdf" ></iframe>