deleteObjects() public method

删除同一个Bucket中的多个Object
public deleteObjects ( string $bucket, array $objects, array $options = null ) : OSS\Http\ResponseCore
$bucket string bucket名称
$objects array object列表
$options array
return OSS\Http\ResponseCore
Ejemplo n.º 1
0
 public function tearDown()
 {
     if (!$this->ossClient->doesBucketExist($this->bucket)) {
         return;
     }
     $objects = $this->ossClient->listObjects($this->bucket, array('max-keys' => 1000, 'delimiter' => ''))->getObjectList();
     $keys = array();
     foreach ($objects as $obj) {
         $keys[] = $obj->getKey();
     }
     if (count($keys) > 0) {
         $this->ossClient->deleteObjects($this->bucket, $keys);
     }
     $uploads = $this->ossClient->listMultipartUploads($this->bucket)->getUploads();
     foreach ($uploads as $up) {
         $this->ossClient->abortMultipartUpload($this->bucket, $up->getKey(), $up->getUploadId());
     }
     $this->ossClient->deleteBucket($this->bucket);
 }
 /**
  * Delete a directory.
  *
  * @param string $dirname
  * @return bool
  */
 public function deleteDir($dirname)
 {
     $list = $this->listContents($dirname, true);
     $objects = [];
     foreach ($list as $val) {
         if ($val['type'] === 'file') {
             $objects[] = $this->applyPathPrefix($val['path']);
         } else {
             $objects[] = $this->applyPathPrefix($val['path']) . '/';
         }
     }
     try {
         $this->client->deleteObjects($this->bucket, $objects);
     } catch (OssException $e) {
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
/**
 * 批量删除object
 *
 * @param OssClient $ossClient OssClient实例
 * @param string $bucket 存储空间名称
 * @return null
 */
function deleteObjects($ossClient, $bucket)
{
    $objects = array();
    $objects[] = "oss-php-sdk-test/upload-test-object-name.txt";
    $objects[] = "oss-php-sdk-test/upload-test-object-name.txt.copy";
    try {
        $ossClient->deleteObjects($bucket, $objects);
    } catch (OssException $e) {
        printf(__FUNCTION__ . ": FAILED\n");
        printf($e->getMessage() . "\n");
        return;
    }
    print __FUNCTION__ . ": OK" . "\n";
}