humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.92k stars 389 forks source link

getObjectAttributes() still downloads full file and Error parsing XML #598

Open SeBsZ opened 2 years ago

SeBsZ commented 2 years ago

Hi there,

I'm trying to use $s3->getObjectAttributes() to grab a file's ETag but I see two issues with this. It seems (based on bandwidth) that this command still downloads the whole file which beats the purpose of just getting the attributes. Secondly, I'm getting an error.

The code and command I'm using:

$s3 = S3_Uploads\Plugin::get_instance()->s3();
        try {
            $data = $s3->getObjectAttributes(
                [
                    'Bucket' => S3_UPLOADS_BUCKET,
                    'Key'    => $key,
                    'ObjectAttributes' => array('ETag')
                ]
            );
            ...

This gives me an error:

"Error parsing response for GetObjectAttributes: AWS parsing error: Error parsing XML: String could not be parsed as XML"

My S3 provider is us-east-1.linodeobjects.com and I'm on version "humanmade/s3-uploads": "3.0.4". I think it's also good to know that if I use $s3->getObject() the command works and I get the Guzzle stream as well as ETag, etc. (but my goal here is not to download the file).

If I change the 'ObjectAttributes' to 'ObjectAttributes' => array('ETag', 'ObjectSize') then it immediately fails with:

"Error executing "GetObjectAttributes" on "path?attributes"; AWS HTTP error: Client error: GET https://path?attributes resulted in a 403 Forbidden response: <?xml version="1.0" encoding="UTF-8"?>SignatureDoesNotMatchtx00000000000001b570a59-0062fe (truncated...)

Hopefully someone can help me out, thanks!