Delete multiple objects Amazon s3 PHP SDK

依然范特西╮ 提交于 2019-12-05 23:23:30

It actually looks like you are not referencing the files (S3 objects) correctly. The formatting of the request is fine, but the bucket name and keys may be wrong.

Looking at:

$bucket = 'teamite/team'.$task['team'];

Is your bucket called "teamite/team1" or just "teamite"? Keep in mind that S3 has a flat structure. There are no "subbuckets". If you have things laid out in a nested file structure, then the paths, or pseudo-folders, need to be included as part of the key.

For example, in this imaginary URL to an object in S3: http://s3.amazonaws.com/all-of-my-things/photos/2013/12/photo0005.jpg

The bucket is all-of-my-things, and the key is photos/2013/12/photo0005.jpg.

The deleteObjects() call you are making is returning successfully because of the idempotent nature of S3 operations. If you delete an object multiple times, it will return successfully every time. What you are seeing here is that you are deleting objects using the wrong keys. Those keys don't exist, and therefore are already deleted.

Hopefully this helps. Don't be afraid to reach out on the module's issue tracker or directly on the SDK's issue tracker for problems like this when you are working directly with the SDK objects.

To delete s3 file use it

It work for me -

 $s3 = AWS::get('s3');
 $s3->deleteMatchingObjects('Your Bucket Name', 'File name to delete');

For testing try:

if(!$s3->deleteObjects(array(
            'Bucket'  => $bucket,
            'Objects' => $json['attachmentArray']
        ))) {
 return "error";
} else {
 return "success";
}

catch will only return "There was an error" if an exception occurs, not if the deleteObjects() method returns false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!