I have a laravel 5.7 project where I am trying to render an image to the browser.
If I just take the content of the file, it works as below:
$contents = Storage::disk($file->disk)->get($file->path);
$new = 'data:'.$file->mimetype.';base64,' . base64_encode($contents);
echo '<img src="'. $new .'">';
By using the above code I can see the image as the way we see in a html file with img tag. But I don't want this!
I want to render the image only as way we see an image in the browser! So I am trying to attach the header type as below:
$contents = Storage::disk($file->disk)->get($file->path);
return response($contents)
->header('Content-Type', $file->mimetype)
->header('Content-Disposition', 'inline;');
The above code does not work and I get error as "The image [url] can not be displayed, because it contains error";
I have no clue what I am mising here!
I don't want to keep those image files in public area and PDF file works fine with same approch.