tencent cloud

Cloud Object Storage

동향 및 공지
릴리스 노트
제품 공지
제품 소개
제품 개요
기능 개요
적용 시나리오
제품 장점
기본 개념
리전 및 액세스 도메인
규격 및 제한
제품 요금
과금 개요
과금 방식
과금 항목
프리 티어
과금 예시
청구서 보기 및 다운로드
연체 안내
FAQ
빠른 시작
콘솔 시작하기
COSBrowser 시작하기
사용자 가이드
요청 생성
버킷
객체
데이터 관리
일괄 프로세스
글로벌 가속
모니터링 및 알람
운영 센터
데이터 처리
스마트 툴 박스 사용 가이드
데이터 워크플로
애플리케이션 통합
툴 가이드
툴 개요
환경 설치 및 설정
COSBrowser 툴
COSCLI 툴
COSCMD 툴
COS Migration 툴
FTP Server 툴
Hadoop 툴
COSDistCp 툴
HDFS TO COS 툴
온라인 도구 (Onrain Dogu)
자가 진단 도구
실습 튜토리얼
개요
액세스 제어 및 권한 관리
성능 최적화
AWS S3 SDK를 사용하여 COS에 액세스하기
데이터 재해 복구 백업
도메인 관리 사례
이미지 처리 사례
COS 오디오/비디오 플레이어 사례
데이터 다이렉트 업로드
데이터 보안
데이터 검증
빅 데이터 사례
COS 비용 최적화 솔루션
3rd party 애플리케이션에서 COS 사용
마이그레이션 가이드
로컬 데이터 COS로 마이그레이션
타사 클라우드 스토리지 데이터를 COS로 마이그레이션
URL이 소스 주소인 데이터를 COS로 마이그레이션
COS 간 데이터 마이그레이션
Hadoop 파일 시스템과 COS 간 데이터 마이그레이션
데이터 레이크 스토리지
클라우드 네이티브 데이터 레이크
메타데이터 가속
데이터 레이크 가속기 GooseFS
데이터 처리
데이터 처리 개요
이미지 처리
미디어 처리
콘텐츠 조정
파일 처리
문서 미리보기
장애 처리
RequestId 가져오기
공용 네트워크로 COS에 파일 업로드 시 속도가 느린 문제
COS 액세스 시 403 에러 코드 반환
리소스 액세스 오류
POST Object 자주 발생하는 오류
보안 및 컴플라이언스
데이터 재해 복구
데이터 보안
액세스 관리
자주 묻는 질문
인기 질문
일반 문제
과금
도메인 규정 준수 문제
버킷 설정 문제
도메인 및 CDN 문제
파일 작업 문제
로그 모니터링 문제
권한 관리
데이터 처리 문제
데이터 보안 문제
사전 서명 URL 관련 문제
SDK FAQ
툴 관련 문제
API 관련 문제
Agreements
Service Level Agreement
개인 정보 보호 정책
데이터 처리 및 보안 계약
연락처
용어집
문서Cloud Object Storage

Copying and Moving Objects

포커스 모드
폰트 크기
마지막 업데이트 시간: 2024-02-04 14:25:57

Overview

This document provides an overview of APIs and SDK code samples for copying and moving an object.
API
Operation
Description
Copying an object (modifying object attributes)
Copies a file to a destination path
Copying a part
Copies an object as a part.
Deleting an object
Deletes a specified object from a bucket.

Advanced APIs (Recommended)

Copying objects

Feature description

This API is used to copy an object. It calls the PUT Object - Copy API for small files, and the Upload Part - Copy API for large files. This API is usually used to modify object attributes. For the parameters required, see those of the PUT Object - Copy and Upload Part - Copy APIs.

Sample request

Sample 1. Copying an object

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->Copy(
$bucket = 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
$key = 'exampleobject', // Object key
$copySorce = array(
'Region' => 'COS_REGION',
'Bucket' => 'sourcebucket-1250000000',
'Key' => 'sourceobject',
)
);
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Sample 2. Changing the object storage class

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->Copy(
$bucket = 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
$key = 'exampleobject', // Object key
$copySorce = array(
'Region' => 'COS_REGION',
'Bucket' => 'examplebucket-1250000000',
'Key' => 'exampleobject',
),
$options = array(
'StorageClass' => 'Archive'
)
);
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Sample 3. Modifying object storage attributes

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->Copy(
$bucket = 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
$key = 'exampleobject', // Object key
$copySorce = array(
'Region' => 'COS_REGION',
'Bucket' => 'sourcebucket-1250000000',
'Key' => 'sourceObject',
),
$options = array(
'MetadataDirective' => 'Replaced',
'Metadata' => array(
'string' => 'string',
),
)
);
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Simple Copy

Copying an object

This API (PUT Object - Copy) is used to copy an object to the destination path.

Method prototype

public Guzzle\\Service\\Resource\\Model copyObject(array $args = array());

Sample request

Sample 1. Copying an object

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->copyObject(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
'CopySource' => 'sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject',
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Sample 2. Copying a specified version of an object

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->copyObject(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
'CopySource' => 'sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject?versionId=MTg0NDUxNjI3NTM0ODE2Njc0MzU',
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Sample 3. Modifying the storage class to ARCHIVE

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->copyObject(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
'CopySource' => 'sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject',
'StorageClass' => 'Archive'
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Sample 4. Modifying metadata

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->copyObject(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
'CopySource' => 'sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject',
'MetadataDirective' => 'Replaced',
'Metadata' => array(
'key1' => 'value1',
'key2' => 'value2',
)
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Parameter description

Parameter Name
Type
Description
Required
Bucket
String
Bucket name in the format of BucketName-APPID
Yes
Key
String
Object key is the unique identifier of an object in a bucket. For example, in the object’s access domain name
examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg, the Key is doc/pic.jpg.
Yes
CopySource
String
Path of the source object, which contains APPID, Bucket, Key, and Region,
such as examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg
Yes
MetadataDirective
String
Valid values: Copy: ignores the configured metadata and copies the file directly; Replaced: modifies the metadata according to the configured metadata. If the destination path is identical to the source path, this parameter must be set to Replaced.
No

Multipart Copy

Note:
This section presents all relevant APIs which are the same as those in Uploading Objects.

Querying a part

Feature description

This API (List Multipart Uploads) is used to query in-progress multipart uploads in a specified bucket.

Method prototype

public Guzzle\\Service\\Resource\\Model listMultipartUploads(array $args = array());

Sample request

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->listMultipartUploads(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Delimiter' => '/',
'EncodingType' => 'url',
'KeyMarker' => 'prfixKeyMarker',
'UploadIdMarker' => 'string',
'Prefix' => 'prfix',
'MaxUploads' => 1000,
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Parameter description

Parameter Name
Type
Description
Required
Bucket
String
Bucket name in the format of BucketName-APPID
Yes
Delimiter
String
Delimiter, left empty by default. For example, you can set it to / to indicate folders.
No
EncodingType
String
Encoding method of the returned value. The value is not encoded by default. Valid value: url
No
KeyMarker
String
The key of the object after which the returned part list begins
No
UploadIdMarker
String
The upload ID of the object after which the returned part list begins
No
Prefix
String
Key prefix to query parts by, left empty by default
No
MaxUploads
Int
Maximum number of returned parts, which is 1000 (the maximum value allowed) by default
No

Response description

Parameter Name
Type
Description
Parent Node
Bucket
String
Bucket name in the format of BucketName-APPID
None
IsTruncated
Int
Whether the returned objects are truncated
None
Uploads
Array
List of returned parts
None
Upload
Array
Attributes of the returned parts
Uploads
Key
String
Object key
Upload
UploadId
String
ID of the multipart upload
Upload
Initiator
String
Initiator of the multipart upload
Upload
Owner
String
Owner of the parts
Upload
StorageClass
String
Storage class of the parts
Upload
Initiated
String
Initiation time of the multipart upload
Upload

Initializing multipart upload

Feature description

This API (Initiate Multipart Upload) is used to initialize a multipart upload.

Method prototype

public Guzzle\\Service\\Resource\\Model createMultipartUpload(array $args = array());

Sample request

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->createMultipartUpload(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Parameter description

Parameter Name
Type
Description
Required
Bucket
String
Bucket name in the format of BucketName-APPID
Yes
Key
String
Object key is the unique identifier of an object in a bucket. For example, in the object’s access domain name
examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg, the Key is doc/pic.jpg.
Yes
CacheControl
String
Cache policy
No
ContentDisposition
String
File name
No
ContentEncoding
String
Encoding format
No
ContentLanguage
String
Language type
No
ContentLength
Int
Length of the content
No
ContentType
String
Content type
No
Expires
String
Content-Expires
No
Metadata
Array
User-defined file metadata
No
StorageClass
String
Storage class of the object, such as STANDARD (default), STANDARD_IA, and ARCHIVE. For more information, see Storage Class Overview.
No
ContentMD5
Boolean
Whether to upload the MD5 checksum of the file for verification
No
ServerSideEncryption
String
Server-side encryption method
No

Response description

Parameter Name
Type
Description
Parent Node
Bucket
String
Bucket name in the format of BucketName-APPID
None
Key
String
Object key
None
UploadId
String
ID of the multipart upload
None

Copying an object part

Feature description

This API (Upload Part - Copy) is used to copy a part of an object.

Method prototype

public Guzzle\\Service\\Resource\\Model uploadPartCopy(array $args = array());

Sample request

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->uploadPartCopy(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
'CopySource' => 'sourcebucket-1250000000.cos.ap-guangzhou.myqcloud.com/sourceObject',
'CopySourceRange' => 'bytes=0-1', // Copy only the first 2 bytes
'UploadId' => 'exampleUploadId', // ID of the multipart upload, which you can get in the response returned after multipart upload initialization
'PartNumber' => 1, // Sequential number of a part, which COS uses to reassemble parts
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Parameter description

Parameter Name
Type
Description
Required
Bucket
String
Bucket name in the format of BucketName-APPID
Yes
Key
String
Object key
Yes
UploadId
String
ID of the multipart upload, which you can get in the response returned after multipart upload initialization
Yes
CopySource
String
Path to the source object, which contains APPID, Bucket, Key, and Region,
for example, examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg
Yes
CopySourceRange
String
Byte range of the source object to copy in the format of bytes=first-last. If no range is specified, the entire source object will be copied.
No
PartNumber
Int
Sequential number of a part, which COS uses to reassemble parts
Yes
ContentLength
Int
Length of the content
No
ContentMD5
Boolean
Whether to upload the MD5 checksum of the file for verification
No

Sample response

Guzzle\\Service\\Resource\\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[ETag] => "96e79218965eb72c92a549dd5a330112"
[LastModified] => "2017-09-04T04:45:45"
[RequestId] => NWNhNDdjYWFfNjNhYjM1MGFfMjk2NF8xY2ViMWM=
[CRC] => 16749565679157681890
)

)

Response description

Parameter Name
Type
Description
Parent Node
ETag
String
MD5 checksum of the part
None
LastModified
String
Time when the object was last modified, in GMT format
None
CRC
String
CRC64 check code for data verification
No

Completing multipart upload

Feature description

This API (Complete Multipart Upload) is used to complete the multipart upload of a file.

Method prototype

public Guzzle\\Service\\Resource\\Model completeMultipartUpload(array $args = array());


Sample request

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->completeMultipartUpload(array(
'Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
'UploadId' => 'exampleUploadId',
'Parts' => array(
array(
'ETag' => 'exampleETag',
'PartNumber' => 1,
)),
// ... repeated
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}

Parameter description

Parameter Name
Type
Description
Required
Bucket
String
Bucket name in the format of BucketName-APPID
Yes
Key
String
Object key
Yes
UploadId
String
ID of the multipart upload
Yes
Parts
Array
List of parts
Yes
Part
Array
Information of the uploaded parts
Yes
ETag
String
MD5 checksum of the part
Yes
PartNumber
Int
Part number
Yes

Moving an Object

Object movement involves copying the source object to the target location and deleting the source object.
Since COS uses the bucket name (Bucket) and object key (ObjectKey) to identify objects, moving an object will modify the object identifier. COS’s PHP SDK does not provide a stand-alone API to modify object identifiers. However, you can still move the object with a combination of basic operations (object copy and object delete).
For example, if you want to move the picture.jpg object to the “doc” directory that is in the same bucket (mybucket-1250000000), you can copy the picture.jpg to the “doc” directory (making the object key doc/picture.jpg) and then delete the source object.
Likewise, if you need to move picture.jpg in the mybucket-1250000000 bucket to another bucket myanothorbucket-1250000000, you can copy the object to the myanothorbucket-1250000000 bucket first and then delete the source object.

Sample code

//: # ".cssg-snippet-move-object"
<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual `SecretId`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual `SecretKey`, which can be viewed and managed in the CAM console at https://console.tencentcloud.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual `region`, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'schema' => 'https', // Protocol header, which is http by default
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$cosClient->copy(
$bucket = 'examplebucket-125000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
$key = 'exampleobject',
$copySource = array(
'Region' => '<sourceRegion>',
'Bucket' => '<sourceBucket>',
'Key' => '<sourceKey>',
)
);
$result = $cosClient->deleteObject(array(
'Bucket' => 'examplebucket-125000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
'Key' => 'exampleobject',
));
// Request succeeded
print_r($result);
} catch (\\Exception $e) {
// Request failed
echo($e);
}


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백