RuwanthaSameera
RuwanthaSameera

Reputation: 113

Angular Frontend display Laravel backend stored image

I want to display image in frontend (Angular).But that image stored in Laravel(5.5) backend.I already try.What should i do? enter image description here

This is error enter image description here

Upvotes: 0

Views: 3145

Answers (2)

Shahid Neermunda
Shahid Neermunda

Reputation: 1357

If your image stored in Storage folder of Laravel.Then create this route in route route.php (if your using above Laravel 5.4, in web.php)

Route::get('images/{filename}', function ($filename)
{
    $file = \Illuminate\Support\Facades\Storage::get($filename);
    return response($file, 200)->header('Content-Type', 'image/jpeg');
});

Now you can load your image using this route like this.

<img src="websiteurl/images/filename.jpg"/>

If image stored in public folder, you can load it directly

   <img src="websiteurl/admin/images/uploads/filename.jpg"/>

You need to run both of your Laravel(Backend) and Angular(Frontend) Application same time (based on your code)

Upvotes: 2

Dan
Dan

Reputation: 102

The storage_path()

function returns the fully qualified path to the storage directory:

$path = storage_path();

Then:

<img src="{{$path}}/{{beer.image}}.ext">

or

<img src="{{storage_path()}}/{{beer.image}}.ext">

Is probably better practice. You also need the file extension.

Upvotes: 0

Related Questions