Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3 DeleteObject - DeleteMarker always returns empty

I am using the AWS SDK for PHP, version 2.4.7 installed via composer. After deleting a file from an S3 bucket the DeleteMarker key in the response object is always empty even through the file has actually been deleted from S3. The documentation states that DeleteMarker should be true if the operation was successful otherwise it's false.

My delete call is:

    // delete S3 object
    $result = $s3->deleteObject(array(
        'Bucket' => $this->_bucket,
        'Key' => $object_key,
    ));

and the response is:

Guzzle\Service\Resource\Model Object
(
    [structure:protected] =>
    [data:protected] => Array
        (
            [DeleteMarker] =>
            [VersionId] =>
            [RequestId] => 2CC3EC60C4294CB5
        )
)

If I then do:

    // check if was deleted
    $is_deleted = (bool) $result->get('DeleteMarker');

$is_deleted is always false. How can it be that there is no value returned against the DeleteMarker key even though the delete operation was actually successful and the file was removed from S3?

UPDATE:

If I add a slash to the start of my key I get a response false back even though the file is still removed from S3.

Key "path/to/my/image.jpg" results in DeleteMarker having empty value Key "/path/to/my/image.jpg" results in DeleteMarker having empty false

But in both cases the images is removed from the S3 bucket.

like image 288
Adrian Walls Avatar asked Oct 23 '13 08:10

Adrian Walls


1 Answers

In converting from SDK v. 1.? to 2.?, I too ran into the problem of not knowing if the file deleted (there used to be the ->isOK() method on just about everything that would let me know if the file had been deleted or not).

I finally stumbled upon this response from the Guzzle creator: https://forums.aws.amazon.com/thread.jspa?messageID=455154

Basically, there is no longer any 'did delete' flag of any kind. What Michael (Guzzle) suggests is this: if you want to know if a file deleted, use ->deleteObject() and then run ->doesObjectExist() to see if the delete was successful.

The rationale for the change is this: the new approach lets you fire off tons of delete requests without having to wait for replies, etc.

For what it's worth. David

like image 152
David M Avatar answered Sep 21 '22 05:09

David M