404 not found file iframe display in laravel after deploying - laravel

I'm trying to view a file that I have uploaded in a view but it shows 404 Not Found. It works fine in local but when I deploy it on heroku this error occurs. I tried php artisan storage:link but it is not working as well. This is the storage directory for the file:
storage/app/public/final_report/2_1_1_1613557659_Ruby Essay.pdf
My Controller:
//get the path for the current Peer Marks final report
$peer_final_report_path = $peer_assignment->final_report['path'];
$peer_final_report_path = "/storage/".$peer_final_report_path;
which the $peer_final_report_path will be /storage/final_report/2_1_1_1613557659_Ruby Essay.pdf
My View:
<!--Display peer marks final report using iframe-->
<div class="card-body" style="float:left;margin-top; 200px;">
<iframe id="pdf-document"
src="{{$peer_final_report_path}}" width="580px" height="800px" >
This browser does not support PDFs. Please download the PDF to view it: Download PDF
</iframe>
</div>
All help will be much appreciated.

Just try something like this.
Storage::url($yourfilepath);

Related

Images not showing up in laravel

So I have images working on my dev environment, however when i try to see them on the production server I receive a 404 error, the images are located in storage/app/public folder, I have ran the following command:
php artisan storage:link
The output says it works however it is still a 404 error when navigating to /storage/imagefolder/image on the site
Technically images are accessible through the public folder, not the storage folder.
In your Code you can access them like:
<img src="{{ asset('imagefolder/image') }}" />
You can find the correct/final image url with:
dd(asset('imagefolder/image'));
First delete the old symlink
Then from the command:
php artisan storage: link
And to display files: ‌
<img src="{{ asset('imagefolder/fileName') }}" />
or
<img src="{{ /storage/imagefolder/fileName }}" />
File permission error on the existing link to storage from the public folder, deleting the link and re running the command fixed the issue.

Laravel storage path isn't accesisble. How to access it from url?

In a laravel I currently have a file saving to the storage directory.
The file appears here
"myroot/storage/app/public/attribute_item/3pCPNl7XaJpIsryhRuVYPdqNp4rKknU737mQ3bGz.svg"
I can visually confirm it's there.
I then attempt to load this up with the following url which is stored in my db:
<img src="{{ asset('storage/app/public/'. $item->image_path) }}" height="50" width="50" onClick="selectImage(this)" style="cursor: pointer;"/>
This gives me a 404 that it doesn't exist. The request url it's attempting to get is this:
http://127.0.0.1:8000/storage/app/public/attribute_item/3pCPNl7XaJpIsryhRuVYPdqNp4rKknU737mQ3bGz.svg
What am I missing here? Is there a specific way I have to call a storage asset?
I was missing this part: php artisan storage:link
This creates the symlink so it will be viewable publicly.
More info found here:
laravel.com/docs/8.x/filesystem#the-public-disk

After Upgrading Wamp Images in Storage Not Showing 404 not found

I am facing a weird problem I am recently upgraded wamp server , but i find out that image dosn't load as it was before upgrading , when I open the image URL in the browser it showing error 404 : page not found
here is my code :
<img src="{{ asset('storage/profile_pics/'.$user->profile_pic) }}" class="img-responsive" alt=""> </div>
any help ?
in your .env file add your APP_URL = to your root folder url which u use to get to your laravel app through WAMP server.
if it doesn't work
You can configure the asset URL host by setting the ASSET_URL variable in your .env file. This can be useful if you host your assets on an external service like Amazon S3:
// ASSET_URL=http://example.com/assets
$url = asset('img/photo.jpg'); // http://example.com/assets/img/photo.jpg
according to this:-
https://laravel.com/docs/5.7/helpers#method-asset
P.S: if you use the command
php artisan serve
and update your APP_URL in your .env file to localhost:8000 , it will work just fine.

Laravel - link to a file saved in storage folder

When we do something like this:
Storage::disk('local')->put('file.txt', 'Contents');
How do you make a link to that file in a view? Something like this:
Download File
there are so many things in documentation and yet not even one example how to create a link to that file
Try this command on your terminal : php artisan storage:link, then laravel storage become public access.
Download File
UPDATE:
According to laravel docs, You can get the URL to the file like this:
use Illuminate\Support\Facades\Storage;
$url = Storage::url('file1.jpg');
Remember, if you are using the local driver, all files that should be
publicly accessible should be placed in the storage/app/public
directory. Furthermore, you should create a symbolic link at
public/storage which points to the storage/app/public directory.
Hope this helps!
Scenario--(working from a fresh Laravel 5.6 project install for reference):
With the existing default paths being /public and /storage/app/public and you want to physically store your logo.png image in the /storage folder and render it on your Welcome page, the process would go something like this:
In your terminal, navigate to your Laravel project folder.
Run command php artisan storage:link
Now create the folder /images in your /storage/app/public folder which gives you /storage/app/public/images.
Look in your /public folder and you will see the (shortcut) subfolders /storage/images
Copy a test image named logo.png into the /storage/app/public/images folder.
In your project's welcome.blade.php under /resources/views paste the
following code over the existing code:
<div class="content">
<div class="title m-b-md">
Laravel
<div>
<a href="/">
<img src="{{url('/storage/images/logo.png')}}" alt="Logo Image"/>
</a>
</div>
</div>
</div>
Save and open your project in your browser and you should see the logo image.
Having said all of that, later on you need a pdf folder to store uploaded pdf
files. Easy, just create a new folder in /storage/app/public called /pdf and
automatically the shortcut will appear in the /public folder. It is a once and "for all" solution.

Image not displaying in view. Laravel

In my Laravel project I'm trying to load an image into my view using blade but it displays as a broken link. I inspect it with firebug and the src is pointing to the image but nothing is displaying.
My image is located in my project's public/images/users/3/profilePictures/
Here is my <img> in the view.blade.php
<img class="com-profile-picture" src="images/users/{{ $follower->id }}/profilePictures/50thumb-{{ $follower->profilePicture->url }}" alt="{{ $follower->first_name }} {{ $follower->last_name }} Profile" width="50" height="50">
However I get this when I load the page:
When I inspect the image with firebug I see this:
That is the correct src and the image does exist in my public/images/users/3/profilePictures/ directory
Anyone know why this is happening?
This may be caused you are in a route which does not represent the base URL. You should generate the URL for your assets relative to the public/ folder. Use URL::asset('path/to/asset') to generate the URL.
{{ URL::asset("images/users/{$follower->id}/profilePictures/50thumb-{$follower->profilePicture->url}") }}
Or as #lukasgeiter mentioned you can simply use asset('path/to/asset') helper.
You can try with the
php artisan storage:link
else you can use this
A simple fix for the issue (linked broken error)
in .env file
APP_URL=http://localhost
this replace with the
APP_URL=http://localhost:8000
then the issue will be fixed.
delete already generated symlink and then run this command
php artisan storage:link
if you are using laravel, consider excluding public folder or any folder where your public files are store in .htacccess from folders that laravel control.
Do it like this in .htaccess
# Exclude directory from rewriting RewriteRule ^(public/) - [L]
Storage location before (Not Working) :
<img src="{{asset('storage/app/public/media/productImages/'.$list->image)}}" alt="" srcset="">
Working storage location :
<img src="{{asset('storage/media/productImages/'.$list->image)}}" alt="" srcset="">
Else try :
Deleting all the linked/shortcut folders created in public folder
Then recreating the link by running :
php artisan storage:link

Resources