如何在刀片Laravel 5.2中显示来自AWS S3的图像 [英] How to display image from aws s3 in blade laravel 5.2

查看:69
本文介绍了如何在刀片Laravel 5.2中显示来自AWS S3的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一种从aws S3获取数据(图像文件)的方法,如下所示:

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';
        }
    }

我确定这些图像存在于aws上,因此没有问题.然后我将上述方法用作刀片视图中的src,如下所示:

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在这里已经指向了AWS上的特定文件,例如:bucket/file.jgp.但是当我运行我的网页时,此Html :: Image给出了这样的视图:

$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 :

这是怎么回事?为什么Html :: image无法渲染我的图像文件?:(

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

推荐答案

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

您可以将S3 URL保存在配置文件中,并使用配置值,而不是每次都写入实际值.

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

这篇关于如何在刀片Laravel 5.2中显示来自AWS S3的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆