Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在blade laravel 5.2中显示aws s3中的图像_Php_Amazon Web Services_Amazon S3_Laravel 5 - Fatal编程技术网

Php 如何在blade laravel 5.2中显示aws s3中的图像

Php 如何在blade laravel 5.2中显示aws s3中的图像,php,amazon-web-services,amazon-s3,laravel-5,Php,Amazon Web Services,Amazon S3,Laravel 5,我创建了一种从aws S3获取数据(图像文件)的方法,如下所示: public static function getImage ($imagePath) { if(Storage::exists($imagePath)) { return Storage::disk('s3')->get($imagePath); }else { return 'No Image';

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

 public static function getImage ($imagePath)
    {
        if(Storage::exists($imagePath))
        {
            return Storage::disk('s3')->get($imagePath);
        }else
        {
            return 'No Image';
        }
    }
我确信aws上存在这些图像,因此没有问题。 然后我在我的刀片视图中使用上述方法作为src,如下所示:

{!!Html::image(getImage($myPath),'logo',['width'=>60,'height'=>55])!!}
此处的$myPath已经指向aws上的特定文件,例如:bucket/file.jgp。但是,当我运行我的网页时,这个Html::Image提供了如下视图:


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

您可以使用
Storage::url($imagePath)
。请参阅laravel文档上的
{!!Html::image(.$myPath),'logo',['width'=>60,'height'=>55])
{!!Html::image(<Your S3 bucket URL>.$myPath),'logo',['width'=>60,'height'=>55])!!}

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

我也有同样的问题。这个代码片段解决了这个问题

<img src="{!! url(<path to your image>) !!}" />
)" />
适用于Laravel 6.x

<img src="{{Storage::disk('s3')->url($imagePath)}}">
url($imagePath)}>

首先,您需要在控制器中对其进行公开宣传

$path = Storage::disk('s3')->put('profileImages/', $request->file('profile_image'), 'public');

//save image name in database
$user->profile_image = basename($path);
刀片式锉刀

<img src="{{Storage::disk('s3')->url('profileImages/' . $user->profile_image)}}" />
url('profileImages/'.$user->profile\u image)}/>

您可以添加像follow这样的访问者来获取图像URL

它返回图像的URL,您可以通过$profile->image访问它

public function getImageAttribute($value)
{
    if ($value) {

        return Storage::disk('s3')->url($value);
    }

    return "https://source.unsplash.com/96x96/daily";
}
我假设您将图像保存为如下所示

$path = $request->file('image')->store('images', 's3');
        
Storage::disk('s3')->setVisibility($path, 'public');

$profile->update([
      'image' =>  $path
      ]);
您可以检查此提交以了解更多详细信息


我已经阅读了所有的解决方案,但没有人直接指出。所以我想写下我的答案。对于这个问题,我只需要添加这条简单的线,然后砰的一声,它就开始工作了。但是我收到了拒绝访问警报,你也应该检查这个问题

<img class="img-responsive" src="{!! Storage::disk('s3')->url('thumbs/' . $business->image->path) !!}" alt="thumb">
url('thumbs/。$business->image->path)!!“alt=”thumb“>
这很有效
Storage::disk('s3')->url($imagePath)

也可以从你的迷你浏览器


您必须
读写

添加
策略
{{HTML::image($myPath)}
如果我只使用HTML::image($myPath),它会给出一个空图像…:)<代码>返回存储::磁盘('s3')->get($imagePath)
返回图像的原始字符串内容
HTML::image
似乎不支持不正确的
raw
<代码>存储::磁盘()->get()
将返回原始图像内容字符串。存储::url未定义。。。我不能使用它,所以我使用的是Storage::disk()->get:)<代码>存储::磁盘('s3')->url($filePath)
应该可用。然后显示图像只需要将image
src
标记设置为此方法的结果感谢您的答案@Vikas。。。我这里似乎有一个bucket权限问题..:在将图像存储到S3
Storage::disk('S3')->put('file.jpg',$contents,'public')时,还应该设置可见性。哦哦。。。我明白了。。。好的。。。让我把“公开”放在那里…:Dmmm。。。是一样的。。。。在发布“public”后仍然存在权限问题……:'(不确定是什么问题,那就是你的回购?我想知道为什么你在模型中将返回设置为url,如果在我的情况下,我存储到S3,但我尝试从“posts”返回“image\u url”,我应该如何在刀片视图中键入它。)表?非常感谢!是的@Eduardo,这是我的回复。我返回是因为它是访问器。现在在blade中,我可以通过
image}>