How to access an image that went to my uploads folder via Fileupload

Asked

Viewed 1,194 times

0

I have a form what makes uploads of images , when I upload , the path is saved in the database by the field path , I recover from the bench this image and play in a array image

this.image = data;

now how can I display this image in a HTML using the image.path ??

<img src="{{ image.path }}">

I tried that and it didn’t work

Code of my image controller

$filename = $file->store("uploads/{$idCampaign}/images");
                if (!$agency) { throw new NotFoundHttpException('agency_not_found'); }
                if ($filename) {
                    $image->file_extension = $file->getClientOriginalExtension();
                    $image->filename = $file->getClientOriginalName();
                    $image->path = $filename;
                    $result = $this->service->save($image);

                    $img = new ImageCampaign();
                    $img->setCampaign($campaign);
                    $img->setImage($image);
                    $img->setAgency($agency);
                    $img->fill($request->post());


                    $this->imageCampaignService->save($img);

                    DB::commit();
                    return response()->json($result);

this code inserts the image in the bank

  • if you can put all the code used?

1 answer

0


Take a look at the official documentation: https://laravel.com/docs/5.5/filesystem#file-urls

But when you upload it plays the file in the Storage folder, but only the public folder is publicly visible, so what Laravel indicates to do is create a public/Storage folder and create a symbolic link with the Storage/app/public folder. This way files that are placed in the Storage/app/public can be viewed publicly.

To display becomes easy:

<img src="{{asset('storage/'.$image_name}}">
  • I’ll try this but I still don’t understand how to make a symbolic link

  • Still as per documentation: https://laravel.com/docs/5.5/filesystem#the-public-disk Just run: php Artisan Storage:link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.