S3-Uploads icon indicating copy to clipboard operation
S3-Uploads copied to clipboard

0 (zero) bytes files in s3 after upload

Open gansbrest opened this issue 7 years ago • 6 comments

Hi,

Installed and enabled your plugin on WP 4.7.2 multisite install, created new s3 bucket, IAM user.

Tried to upload a file using media library. It showed up in s3 - https://s3.amazonaws.com/mybucket.com/uploads/sites/3/2017/03/15289118_10153975276332327_12359350734570324_o.jpg

But the file is empty, zero bytes..

What could be the problem?

gansbrest avatar Mar 14 '17 02:03 gansbrest

This seem to be resolved by giving full permissions to s3, probably I missed some important bucket permissions. Is there a dock saying which permissions I need?

Also I noticed that when I delete image in WP, original image is not deleted, only 150x150 and 300x300 copies. Is that by design? ( why? )

gansbrest avatar Mar 15 '17 01:03 gansbrest

Just in case someone finds this and does NOT want to give full admin permissions, and does not use the wp-cli tool provided for creating IAM user. You can restrict user to specific bucket by using the following security policy

    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:PutObjectAclVersion",
                "s3:AbortMultipartUpload",
                "s3:ListBucket",
                "s3:GetObject"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::bucketname-here"
        },
        {
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:PutObjectAclVersion",
                "s3:AbortMultipartUpload",
                "s3:ListBucket",
                "s3:GetObject"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::bucketname-here/*"
        }
    ]
}

mattpramschufer avatar Mar 08 '18 18:03 mattpramschufer

I've also stumbled upon this issue. Changing default acl settings to "private" helped, and "s3:PutObjectAcl" permissions mentioned by @mattpramschufer were unnecessary.

define('S3_UPLOADS_OBJECT_ACL', 'private');

Hope it helps.

ameiji avatar Feb 10 '20 13:02 ameiji

Just in case someone finds this and does NOT want to give full admin permissions, and does not use the wp-cli tool provided for creating IAM user. You can restrict user to specific bucket by using the following security policy

                "s3:PutObjectAcl",
                "s3:PutObjectAclVersion",

Thanks @mattpramschufer!

Ran into the same issue, adding these to the IAM role being used by S3-Uploads corrected the issue.

A bit of a gotcha, unfortunately the PHP error logs don't seem to throw any errors for this kind of issue.

I was using CDK, and incorrectly assumed mediaBucket.grantReadWrite(wordpressLambda) would be enough. Had to add to also add mediaBucket.grantPutAcl(wordpressLambda) to get the above PutObjectAcl* added to the IAM role.

aaronbrighton avatar May 04 '21 14:05 aaronbrighton

I've also stumbled upon this issue. Changing default acl settings to "private" helped, and "s3:PutObjectAcl" permissions mentioned by @mattpramschufer were unnecessary.

define('S3_UPLOADS_OBJECT_ACL', 'private');

Hope it helps.

This helped me fix the issue, this was missing from my config.

dmpinder avatar Oct 09 '21 13:10 dmpinder

Thanks @aaronbrighton, grantPutAcl() was the missing piece for us too!

adambiggs avatar Nov 25 '21 00:11 adambiggs