0

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

11
  • What is the url of the laravel backend? Commented Dec 18, 2018 at 10:48
  • backend/public/admin//images/uploads/image.extention this is the path. Commented Dec 18, 2018 at 10:54
  • laravel url localhost:8000 Commented Dec 18, 2018 at 10:55
  • 1
    @RuwanthaSameera As per the console log you are missing the file extension. Seems beer.image doesn't include extension. Commented Dec 18, 2018 at 12:00
  • if your backend url is localhost:8000, then images will be at localhost:8000/admin/images/uploads Commented Dec 18, 2018 at 13:00

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.