Performing a Multipart Copy
Function
This API allows you to upload a part by copying an object or part of this object.
You can call ObsClient.copyPart to copy parts.
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference.
Restrictions
- To copy an object, you must be the bucket owner or have the required permission (obs:object:PutObject granted using IAM or PutObject granted using a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Configuring an Object Policy.
- You must have the read permission for the source object.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
- The object copy request contains the information about the source bucket and object to be copied in the header. The message body cannot be contained.
- Cross-bucket replication in the same region is supported, but cross-region replication is not supported.
- If the source object is in the Archive storage class, you must restore it first.
Method
ObsClient.copyPart(params)
Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| Bucket | String | Yes | Explanation: Bucket name Restrictions:
Default value: None |
| Key | String | Yes | Explanation: Object name. An object is uniquely identified by an object name in a bucket. An object name is a complete path of the object that does not contain the bucket name. For example, if the address for accessing the object is examplebucket.obs.ap-southeast-1.myhuaweicloud.com/folder/test.txt, the object name is folder/test.txt. Value range: The value must contain 1 to 1,024 characters. Default value: None NOTE: The object URL is in the following format: https://Bucket name.Domain name/Folder directory level/Object name. If this object is stored in the root directory of the bucket, its URL does not contain the folder directory level. |
| RequestDate | String or Date | No | Explanation: Request time NOTE: When the parameter type is String, the value must comply with the ISO8601 or RFC822 standard. |
| PartNumber | Number | Yes | Explanation: Part number Value range: 1 to 10000 Default value: None |
| UploadId | String | Yes | Explanation: Multipart upload ID, which can be obtained by initiating a multipart upload, for example, 000001648453845DBB78F2340DD460D8 Restrictions: The value must contain 32 characters. Default value: None |
| CopySource | String | Yes | Explanation: Specifies the source bucket, source object, and source object version ID (which can be left blank) Restrictions: Format: Source bucket name/Source object name?versionId=Source object version ID Default value: None |
| CopySourceRange | String | No | Explanation: Copy source range Value range: 0 to the source object length minus 1 Restrictions:
Default value: By default, the entire object is copied. |
| SseC | String | No | Explanation: Algorithm used for SSE-C Value range: AES256: SSE-C and the AES-256 algorithm are used. Default value: None |
| SseCKey | String | No | Explanation: Custom key used in SSE-C encryption. The value is a Base64-encoded 256-bit key. Default value: None |
| CopySourceSseC | String | No | Explanation: SSE-C is used for decrypting the source object. Value range: AES256: SSE-C and the AES-256 algorithm are used. Default value: None |
| CopySourceSseCKey | String | No | Explanation: Key used to decrypt the source object in SSE-C mode Default value: None |
Responses
| Parameter | Type | Description |
| Status | number | Explanation: HTTP status code returned by the OBS server Value range: A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For details, see Status Codes. |
| Code | string | Explanation: Error code returned by the OBS server |
| Message | string | Explanation: Error description returned by the OBS server |
| HostId | string | Explanation: Request server ID returned by the OBS server |
| RequestId | string | Explanation: Request ID returned by the OBS server |
| Id2 | string | Explanation: Request ID2 returned by the OBS server |
| Indicator | string | Explanation: Error code details returned by the OBS server |
| Parameter | Type | Description |
|---|---|---|
| ETag | String | Explanation: Base64-encoded 128-bit MD5 digest of a part. ETag is the unique identifier of the part content. It can be used to determine whether the part content is changed. Value range: The value must contain 32 characters. Default value: None |
| LastModified | String | Explanation: Last modification time of the destination part Default value: None |
Sample Code
This example copies a part of object sourceobjectname in bucket sourcebucketname to a part of object destobjectname in bucket destbucketname.
// Create an ObsClient instance.
var obsClient = new ObsClient({
// Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK before storing them in the configuration file or environment variables. In this example, the AK and SK are stored in environment variables. Before running the code in this example, configure environment variables AccessKeyID and SecretAccessKey.
// The front-end code does not have the process environment variable, so you need to use a module bundler like webpack to define the process variable.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
access_key_id: process.env.AccessKeyID,
secret_access_key: process.env.SecretAccessKey,
// CN-Hong Kong is used here in this example. Replace it with the one currently in use.
server: 'https://obs.ap-southeast-1.myhuaweicloud.com'
});
var destBucketName = 'destbucketname';
var destObjectKey = 'destobjectname';
var sourceBucketName = 'sourcebucketname';
var sourceObjectKey = 'sourceobjectname';
obsClient.CopyPart({
Bucket : destBucketName,
Key : destObjectKey,
// Set the part number, which ranges from 1 to 10000.
PartNumber : 1,
// Set the upload ID.
UploadId : 'upload id from initiateMultipartUpload',
// Set the source object to be copied.
CopySource : sourceBucketName + '/' + sourceObjectKey,
// Set the to-be-copied range of the source object.
CopySourceRange : 'bytes=0-100'
}, function(err, result) {
if (err) {
console.log('Error-->' + err);
} else {
console.log('Status-->' + result.CommonMsg.Status);
if (result.CommonMsg.Status < 300 && result.InterfaceResult) {
console.log('RequestId-->' + result.InterfaceResult.RequestId);
console.log('LastModified-->' + result.InterfaceResult.LastModified);
console.log('ETag-->' + result.InterfaceResult.ETag);
}
}
});
- Use the PartNumber parameter to specify the part number, the UploadId parameter to specify the globally unique ID for the multipart upload, the CopySource parameter to specify the information about the source object, and the CopySourceRange parameter to specify the byte range to copy.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot