Home > Software engineering >  How to display an image from s3 bucket in laravel 9
How to display an image from s3 bucket in laravel 9

Time:11-11

I'm trying to create a user profile page. I`ve got it so a user can upload an image and I am currently struggling with how to display that image now.

The only way I could find were the following:

<img src="{{Storage::disk('s3')->url($image_path)}}" style="height:400px !important;" alt="logo">
<img src="{{$image_path}}" style="height:400px !important;" alt="logo">

However, neither of these seems to work and I`m not sure what else to try. My code from my controller to get the image path:

$image_path = Storage::disk('s3')->url(
            "images"."/".$auth_id
        );

My code from my controller to store the images :

public function uploadPost(Request $request){
    $request->validate([
        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
    ]);

    $id = Auth::id();
 
    Storage::disk('s3')->putFileAs('images', $request->image,$id);


    return view("/pages/teachers-page/teacher_profile")
        ->with('success','You have successfully upload image.');
}

CodePudding user response:

I figured it out the code above works as intended. I just needed to change the permissions of my IAM User in AWS.

  • Related