Multipart Uploads

Multipart upload is recommended for large files (usually > 100MB) or environments with unstable network conditions. It splits the file into multiple parts and uploads them independently.

High-Level API

The multiuploadFile method manages the entire process (initiation, part splitting, and completion) for you.

$object = "large-movie.mp4";
$localFile = "/path/to/movie.mp4";

$options = [
    OssClient::OSS_PART_SIZE => 10 * 1024 * 1024, // 10MB parts
    OssClient::OSS_CHECK_MD5 => true,
];

$ossClient->multiuploadFile($bucket, $object, $localFile, $options);

Low-Level API (Manual Control)

If you need granular control (e.g., resuming a failed upload), use the raw APIs.

Step 1: Initiate

$uploadId = $ossClient->initiateMultipartUpload($bucket, $object);

Step 2: Upload Parts

$partSize = 5 * 1024 * 1024;
$parts = [];
// Loop through file segments and call:
$etag = $ossClient->uploadPart($bucket, $object, $uploadId, [
    OssClient::OSS_FILE_UPLOAD => $file,
    OssClient::OSS_PART_NUM => $i,
    OssClient::OSS_SEEK_TO => $offset,
    OssClient::OSS_LENGTH => $length,
]);
$parts[] = ['PartNumber' => $i, 'ETag' => $etag];

Step 3: Complete

$ossClient->completeMultipartUpload($bucket, $object, $uploadId, $parts);

Listing Incomplete Uploads

To find and clean up failed uploads that are consuming storage space:

$info = $ossClient->listMultipartUploads($bucket);
foreach ($info->getUploads() as $upload) {
    // $ossClient->abortMultipartUpload($bucket, $upload->getKey(), $upload->getUploadId());
}