Hyosoka Poipo Hyosoka Poipo - 2 months ago 52
PHP Question

How to display image from aws s3 in blade laravel 5.2

I have created a method for getting the data(image file) from aws S3 like this :

public static function getImage ($imagePath)
{
if(Storage::exists($imagePath))
{
return Storage::disk('s3')->get($imagePath);
}else
{
return 'No Image';
}
}


I'm sure that those image is exist on the aws, so there is no problem with that.
And then I use above method as the src in my blade view like this :

{!!Html::image(getImage($myPath),'logo',['width'=>60,'height'=>55])!!}


$myPath here already point to the specific file on aws for example : bucket/file.jgp. But when I run my webpage, this Html::Image gives a view like this :
enter image description here

What's going on here ? Why Html::image can't render my image file ? :(

Answer
{!!Html::image(<Your S3 bucket URL>.$myPath),'logo',['width'=>60,'height'=>55])!!}

You can save the S3 URL in a config file and use the config value instead of writing actual value everytime.