Uploading Multipart
To upload a large file, multipart upload is recommended. Multipart upload is applicable to many scenarios, including:
- Files to be uploaded are larger than 100 MB.
- The network condition is poor, and the connection to the storage server such as OBS is frequently disconnected.
- Sizes of files to be uploaded are uncertain.
Multipart upload consists of three steps:
- Initializing a Multipart Upload Task: creates a multipart upload task.
- Uploading Parts.
- Completing Multipart Upload or Terminating (Canceling) a Multipart Upload Task.
After the upload is complete, the file is stored in the bucket. If you terminate (cancel) a multipart upload task, all uploaded parts will be discarded.
Initializing a Multipart Upload Task
- Function
Before uploading data in multipart mode, you must create an initial multipart upload task. This operation will return a globally unique identifier (uploadId) of the task to identify the multipart upload task. You can use the identifier to initiate subsequent operations, such as uploading a multipart upload task, merging parts to complete the upload, and terminating (cancelling) the multipart upload task.
- URI
POST Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/{connector_type}/{connector_name}/createmultipartupload?object=X
Table 1 URI parameters Parameter
Mandatory
Type
Description
connector_type
Yes
String
Explanation
Type of a connector.
Constraints
None
Value
- obs: connector for interconnecting with OBS.
- minio: connector for connecting to MINIO.
- objectstorageproxy: object storage proxy type.
Default value
None
connector_name
Yes
String
Explanation
Name of the connector instance, that is, the connector instance name set when the connector is created.
Constraints
None
Value
None
Default value
None
object
Yes
String
Explanation
Full path of the file to be uploaded in the bucket, including the file name, file type, and upload path. If no path is specified, the file is uploaded to the root directory of the bucket.
For example, if the value is a/b/c/test.mp4, the test.mp4 file is uploaded to the a/b/c path of the bucket. If the path does not exist in the bucket, it will be created.
Constraints
None
Value
None
Default value
None
- Request Parameters
Table 2 Request header parameters Header Field
Mandatory
Type
Description
Content-Type
Yes
String
Explanation
Media type of the file to be uploaded. The value must be the same as the file name. For example, if the file name is test.mp4, the value of Content-Type is video/mp4.
Constraints
None
Value
None
Default value
None
- Response Parameters
Table 3 Response parameters Parameter
Type
Description
resCode
String
Explanation
Return code.
Value
If the request is successful, 0 is returned. For details about other error codes, see Error Codes.
resMsg
String
Explanation
Message returned.
Value
If the request is successful, Success is returned. In other cases, an error message is returned.
result
Object
Explanation
Object of the created multipart task is returned. The object contains the uploadId field, which indicates the globally unique identifier of the task and is used to identify the multipart upload task. You can use the identifier to initiate subsequent operations, such as uploading a multipart upload task, merging parts to complete the upload, and terminating (canceling) the multipart upload task.
- Example Request
An OBS connector has been created. The connector instance name is Namespace_TestOBS. Large files need to be uploaded to the a/b/c path of the OBS bucket. Call the following request to initialize the multipart upload task:
POST https://Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/obs/Namespace __TestOBS/createmultipartupload?object=a/b/c/test.mp4
- Example Response
{ "resCode": "0", "resMsg": "Success", "result": { "uploadId": "0000017B761***8FF0F75F13" } }
Record the value of uploadId, which is used to identify the multipart upload task and will be used in subsequent operations.
Uploading Parts
- Function
After Initializing a Multipart Upload Task, you can upload data by part based on the specified object file name and uploadId. Each uploaded part has a part number, which ranges from 1 to 10000. For the same multipart upload task (with the same uploadId), partNumber not only uniquely identifies a part of data, but also identifies its relative location in the object file. If new data is uploaded using the same part number, the existing data of the part number on the storage server will be overwritten. Except for the last part, the sizes of other parts must be greater than 5 MB. The maximum size of each part is not limited by OBS and MINIO. When this API is called through Huawei Cloud Astro Zero, the maximum size of all parts is 100 MB. Parts can be uploaded in sequence or even on different processes or machines. The storage server sorts the parts by part number to form the final object.
- URI
POST Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/{connector_type}/{connector_name}/uploadpart?object=X&uploadId=Y&partNumber=Z
Table 4 URI parameters Parameter
Mandatory
Type
Description
connector_type
Yes
String
Explanation
Type of a connector.
Constraints
None
Value
- obs: connector for interconnecting with OBS.
- minio: connector for connecting to MINIO.
- objectstorageproxy: object storage proxy type.
Default value
None
connector_name
Yes
String
Explanation
Name of the connector instance, that is, the connector instance name set when the connector is created.
Constraints
None
Value
None
Default value
None
object
Yes
String
Explanation
Full path of the file to be uploaded in the bucket, including the file name, file type, and upload path. If no path is specified, the file is uploaded to the root directory of the bucket.
For example, if the value is a/b/c/test.mp4, the test.mp4 file is uploaded to the a/b/c path of the bucket. If the path does not exist in the bucket, it will be created.
Constraints
None
Value
None
Default value
None
uploadId
Yes
String
Explanation
Identifier of the multipart upload task. You can obtain the value from the returned result of Initializing a Multipart Upload Task.
Constraints
None
Value
None
Default value
None
partNumber
Yes
Number
Explanation
Part number
For the same multipart upload task (with the same uploadId), partNumber not only uniquely identifies a part of data, but also identifies its relative location in the object file.
Constraints
None
Value
1–10000
Default value
None
- Request Parameters
Body type in the request. The file part is uploaded in the application/octet-stream format.
- Response Parameters
Table 5 Response parameters Parameter
Type
Description
resCode
String
Explanation
Return code.
Value
If the request is successful, 0 is returned. For details about other error codes, see Error Codes.
resMsg
String
Explanation
Message returned.
Value
If the request is successful, Success is returned. In other cases, an error message is returned.
result
Object
Explanation
Returned multipart task object, which contains the following fields:
- ETag: identifier of a file part, which is used for subsequent upload.
- partNumber: part number, which is used for subsequent upload.
- Example Request
An OBS connector has been created. The connector instance name is Namespace_TestOBS. Large files need to be uploaded to the a/b/c path of the OBS bucket. The multipart upload task whose uploadId is 0000017B761F112966C45D8FF0F75F13 has been initialized. Call the following request to create a multipart upload task and upload the test.mp4 file whose part number is 1.
POST https://Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/obs/Namespace __TestOBS/uploadpart?object=a/b/c/test.mp4&uploadId=0000017B761F112966C45D8FF0F75F13&partNumber=1
In the request body, set the object in the application/octet-stream format, that is, the file data to be uploaded.
- Example Response
{ "resCode": "0", "resMsg": "Success", "result": { "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"", "partNumber": 1 } }
Record the values of ETag and partNumber, which will be used during the upload.
Completing Multipart Upload
- Function
After all parts are uploaded, you need to call the upload completion API to merge parts on the storage server (for example, OBS) to generate the final object file. After the upload is complete, you need to provide a list of all valid parts (including partNumber and ETag). After receiving the submitted part list, Huawei Cloud Astro Zero verifies the validity of each part one by one. After all parts pass the verification, these parts are combined into the final object. The merged multipart tasks can have inconsecutive part numbers.
After the upload is complete, uploadId becomes invalid and cannot be used to terminate (cancel) the multipart upload.
- URI
POST Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/{connector_type}/{connector_name}/completeupload?object=X&uploadId=Y
Table 6 URI parameters Parameter
Mandatory
Type
Description
connector_type
Yes
String
Explanation
Type of a connector.
Constraints
None
Value
- obs: connector for interconnecting with OBS.
- minio: connector for connecting to MINIO.
- objectstorageproxy: object storage proxy type.
Default value
None
connector_name
Yes
String
Explanation
Name of the connector instance, that is, the connector instance name set when the connector is created.
Constraints
None
Value
None
Default value
None
object
Yes
String
Explanation
Full path of the file to be uploaded in the bucket, including the file name, file type, and upload path. If no path is specified, the file is uploaded to the root directory of the bucket.
For example, if the value is a/b/c/test.mp4, the test.mp4 file is uploaded to the a/b/c path of the bucket. If the path does not exist in the bucket, it will be created.
Constraints
None
Value
None
Default value
None
uploadId
Yes
String
Explanation
Identifier of the multipart upload task. You can obtain the value from the returned result of Initializing a Multipart Upload Task.
Constraints
None
Value
None
Default value
None
- Request Parameters
Array type. Each element contains the fields listed in Table 7.
Table 7 Request parameters Parameter
Mandatory
Type
Description
ETag
Yes
String
Explanation
Identifier of a file part. Obtain the value from the result returned by Uploading Parts.
Constraints
None
Value
None
Default value
None
partNumber
Yes
String
Explanation
Part number
For the same multipart upload task (with the same uploadId), partNumber not only uniquely identifies a part of data, but also identifies its relative location in the object file. Obtain the value from the returned result in Uploading Parts.
Constraints
None
Value
1–10000
Default value
None
- Response Parameters
Table 8 Response parameters Parameter
Type
Description
resCode
String
Explanation
Return code.
Value
If the request is successful, 0 is returned. For details about other error codes, see Error Codes.
resMsg
String
Explanation
Message returned.
Value
If the request is successful, Success is returned. In other cases, an error message is returned.
- Example Request
An OBS connector has been created. The connector instance name is Namespace_TestOBS. Large files need to be uploaded to the a/b/c path of the OBS bucket. There are two multipart upload tasks, and uploadId is 0000017B761F112966C45D8FF0F75F13. Call the following request to complete the multipart upload task and merge all parts to generate the final object file.
POST https://Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/obs/Namespace __TestOBS/completeupload?object=a/b/c/test.mp4&uploadId=0000017B761F112966C45D8FF0F75F13 [{ "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"", "partNumber": 1 }, { "ETag": "\"7dcad0c8a7398333ff25418bad511581\"", "partNumber": 2 }]
- Example Response
{ "resCode": "0", "resMsg": "Success" }
Terminating (Canceling) a Multipart Upload Task
- Function Description
After a multipart upload task is canceled, you cannot use its uploadId to perform any operation and the uploaded parts will be deleted.
When a file is being uploaded in multipart mode or fails to be uploaded, parts are generated in the bucket. These parts occupy storage space. You can cancel the multipart upload to delete unnecessary parts to save storage space.
- URI
POST Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/{connector_type}/{connector_name}/abortupload?object=X&uploadId=Y
Table 9 URI parameters Parameter
Mandatory
Type
Description
connector_type
Yes
String
Explanation
Type of a connector.
Constraints
None
Value
- obs: connector for interconnecting with OBS.
- minio: connector for connecting to MINIO.
- objectstorageproxy: object storage proxy type.
Default value
None
connector_name
Yes
String
Explanation
Name of the connector instance, that is, the connector instance name set when the connector is created.
Constraints
None
Value
None
Default value
None
object
Yes
String
Explanation
Full path of the file to be uploaded in the bucket, including the file name, file type, and upload path. If no path is specified, the file is uploaded to the root directory of the bucket.
For example, if the value is a/b/c/test.mp4, the test.mp4 file is uploaded to the a/b/c path of the bucket. If the path does not exist in the bucket, it will be created.
Constraints
None
Value
None
Default value
None
uploadId
Yes
String
Explanation
Identifier of the multipart upload task. You can obtain the value from the returned result of Initializing a Multipart Upload Task.
Constraints
None
Value
None
Default value
None
- Request Parameters
- Response Parameters
Table 10 Response parameters Parameter
Type
Description
resCode
String
Explanation
Return code.
Value
If the request is successful, 0 is returned. For details about other error codes, see Error Codes.
resMsg
String
Explanation
Message returned.
Value
If the request is successful, Success is returned. In other cases, an error message is returned.
- Example Request
An OBS connector has been created. The connector instance name is Namespace_TestOBS. Large files need to be uploaded to the a/b/c path of the OBS bucket. If the uploadId is 0000017B76500F0662CABA7128913936, call the following request to cancel the multipart upload task:
POST https://Huawei Cloud Astro Zero domain name/u-route/baas/sys/v1.1/connectors/obs/Namespace __TestOBS/abortupload?object=a/b/c/test3.mp4&uploadId=0000017B76500F0662CABA7128913936
- Example Response
{ "resCode": "0", "resMsg": "Success" }
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