Skip to content
Advertisement

Image not displaying reactjs laravel

i want to get image from laravel storage and display it in react js

<img src={getImage(item.path)} />

getImage function

const getImage = (path) => {
    const di = axios.get("http://localhost:8000/api/"+path)
        .then(res => {
          return res.data;
        });
    return URL.createObjectURL(new Blob([di]));
}

my laravel controller function

public function download($image)
    {
        $path = "mail/{$image}";
        if(Storage::exists($path)){
            $file = Storage::download($path);
            return Response::make($file, 200);
        }
    }

that what i get

enter image description here

enter image description here

please help me to find solution i have this problem since week

Advertisement

Answer

You should return it like this

return response()->file($file, $headers);
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement