bukxy's avatar
Level 1

AWS unable to post a new file

Hey :), I did an other post to help me on this problem, but now i know the problem but don't know how to solve it...

When i want to store my file in my s3 i have this error : (with store(), storeAs(), Storage::disk('s3')->put('images', $req->file('banner')) )

Error executing "HeadObject" on "http://rankserver.s3.eu-west-3.amazonaws.com/images/64x64.png"; AWS HTTP error: Client error: `HEAD http://rankserver.s3.eu-west-3.amazonaws.com/images/64x64.png` resulted in a `404 Not Found` response NotFound (client): 404 Not Found (Request-ID: 1XAJQNNTE18HJJR3) -

I got this error when i trie to upload an image who don't exist in my s3,

Exemple if in my s3/images i have a file named 64x64.png, i can upload.

BUT

If i try to upload a new file with his hashed name, i can't and i got this error.

I tried to do a new project and same... My user have s3FullAccess

Where this error come ?

0 likes
3 replies
bukxy's avatar
Level 1

@Snapey Controller

public function newStore(Request $req) {
        $req->validate([
            'banner' => 'nullable|mimes:png,jpg,jpeg,gif|dimensions:max_width=200,max_height=200|max:2048',
        ]);

        $banner = $req->file('banner');
        $banner->storeAs('images', $banner->getClientOriginalName(),'s3');
}

Form

<form method="post" action="{{ route('add-server.store') }}" enctype="multipart/form-data">
 <div class="input-group mb-3">
  <div class="col-3">
   <label for="game">Select game</label>
   @error('banner')
   <div class="alert alert-danger">{{ $message }}</div>
   @enderror
  </div>
  <div class="input-group-prepend">
   <span class="input-group-text" id="banner">Banner</span>
  </div>
  <div class="custom-file">
   <input type="file" class="custom-file-input" id="banner" name="banner">
   <label class="custom-file-label" for="banner">Choose file</label>
  </div>
 </div>
</form>

AWS IAM

Only have : AmazonS3FullAccess

AWS S3 bucket POLICY :

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::4.........9:user/rank-server"
            },
            "Action": "*",
            "Resource": "arn:aws:s3:::rankserver/*"
        }
    ]
}

.env

AWS_ACCESS_KEY_ID=A......................P
AWS_SECRET_ACCESS_KEY=C...................v
AWS_DEFAULT_REGION=eu-west-3
AWS_BUCKET=rankserver
AWS_USE_PATH_STYLE_ENDPOINT=false
bukxy's avatar
Level 1

OK, so i don't understand why that doesn't work, but after reinstalling the packing many time, that work...

Please or to participate in this conversation.