wink icon indicating copy to clipboard operation
wink copied to clipboard

S3 Filesystem Not Working

Open intellow opened this issue 6 years ago • 8 comments

I have an s3 bucket successfully configured for my app. It is working for all the non-wink parts of my application.

I've added the following items to my .env:

WINK_STORAGE_DISK=s3
WINK_STORAGE_PATH=wink

However, when I try to upload an image I get the following error:

Error executing "PutObject" on "https://my-bucket.s3.us-west-1.amazonaws.com/wink/mJBwl4ixQzI9qcsLEttzghNapLxaFrquST74I6MQ.jpeg"; AWS HTTP error: Client error: PUT https://my-bucket.s3.us-west-1.amazonaws.com/wink/mJBwl4ixQzI9qcsLEttzghNapLxaFrquST74I6MQ.jpegresulted in a403 Forbidden response: <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>7A693D (truncated...) AccessDenied (client): Access Denied - <?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>7A693D29C79D3BDF</RequestId><HostId>JQEG2o5QcFxqq8oIVQkaGfDJcbBRKojgCmSNFXl0A6k2PlSLadOqVdXNyT4uxmxihXNYxHv9S/E=</HostId></Error>

intellow avatar Feb 13 '19 21:02 intellow

hmm we use it on blog.laravel.com and it seems to be working fine for us. Are you sure you are on the latest Wink?

themsaid avatar Feb 15 '19 11:02 themsaid

hmm we use it on blog.laravel.com and it seems to be working fine for us. Are you sure you are on the latest Wink?

Yep, I just installed it 2 days ago, so I must be on the latest. My S3 policy allows the authenticated user I created in IAM to have access to all S3 actions. Again, those credentials are working in the non-wink aspects of the app. In case this is helpful, here is my S3 bucket policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<my-user>"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::my-bucket/*",
                "arn:aws:s3:::my-bucket"
            ]
        },
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-bucket/*"
        }
    ]
}

intellow avatar Feb 15 '19 20:02 intellow

@intellow I had the same issue and had to uncheck those in my bucket config : image But I don't know if it is a good practice. 😨

Hope it helps!

(So my problem wasn't Wink related, i had the same error when trying to upload files from a controller)

opmvpc avatar Apr 14 '19 10:04 opmvpc

I'm having the same issue as @intellow. @opmvpc Your solution worked for me but I'm curios if this is the best/safest way to handle this.

nlehman06 avatar May 31 '19 22:05 nlehman06

did anyone solve this without changing the public option?

divyamanchireddy19 avatar Oct 08 '20 04:10 divyamanchireddy19

I'm running into this also but I am not able to fix it by making the bucket public.

nolannordlund avatar Feb 10 '21 16:02 nolannordlund

I ended up unchecking every option in the "Block public access" section and I also added the following policy so that Wink could read and write to the bucket:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Public",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:PutObject"
            ],
            "Resource": "arn:aws:s3:::BUCKET_NAME/*"
        }
    ]
}

nolannordlund avatar Feb 10 '21 20:02 nolannordlund

It seems S3 has had some updates, to get Wink to be able to upload images I needed to change the owner-enforced property to owner-preferred and "restore ACLs" image

my policy remains :

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::preview.aeroquote.com/*"
        }
    ]
}

dircm avatar Jul 15 '22 01:07 dircm

In my case, even after modifying bucket permissions, I kept getting the error:

Found 1 error while validating the input provided for the GetObject operation: [Key] expected string length to be >= 1, but found string length of 0

Slightly modifying the upload function in ImageUploadsController seemed to fix the issue. Here's the modification:

public function upload()
{
    $path = Storage::disk(config('wink.storage_disk'))->put(config('wink.storage_path'), request()->image);

    return response()->json([
        'url' => Storage::disk(config('wink.storage_disk'))->url($path),
    ]);
}

aifodu avatar Aug 25 '23 14:08 aifodu