in src/OSS/OssClient.php [2664:2752]
public function multiuploadFile($bucket, $object, $file, $options = null)
{
$this->precheckCommon($bucket, $object, $options);
if (isset($options[self::OSS_LENGTH])) {
$options[self::OSS_CONTENT_LENGTH] = $options[self::OSS_LENGTH];
unset($options[self::OSS_LENGTH]);
}
if (empty($file)) {
throw new OssException("parameter invalid, file is empty");
}
$uploadFile = $this->encodeFilePath($file);
if (!isset($options[self::OSS_CONTENT_TYPE])) {
$options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object, $uploadFile);
}
$upload_position = isset($options[self::OSS_SEEK_TO]) ? (integer)$options[self::OSS_SEEK_TO] : 0;
if (isset($options[self::OSS_CONTENT_LENGTH])) {
$upload_file_size = (integer)$options[self::OSS_CONTENT_LENGTH];
} else {
$upload_file_size = sprintf('%u', filesize($uploadFile));
if ($upload_file_size !== false) {
$upload_file_size -= $upload_position;
}
}
if ($upload_position === false || !isset($upload_file_size) || $upload_file_size === false || $upload_file_size < 0) {
throw new OssException('The size of `fileUpload` cannot be determined in ' . __FUNCTION__ . '().');
}
// Computes the part size and assign it to options.
if (isset($options[self::OSS_PART_SIZE])) {
$options[self::OSS_PART_SIZE] = $this->computePartSize($options[self::OSS_PART_SIZE]);
} else {
$options[self::OSS_PART_SIZE] = self::OSS_MID_PART_SIZE;
}
$is_check_md5 = $this->isCheckMD5($options);
// if the file size is less than part size, use simple file upload.
if ($upload_file_size < $options[self::OSS_PART_SIZE] && !isset($options[self::OSS_UPLOAD_ID])) {
return $this->uploadFile($bucket, $object, $uploadFile, $options);
}
// Using multipart upload, initialize if no OSS_UPLOAD_ID is specified in options.
if (isset($options[self::OSS_UPLOAD_ID])) {
$uploadId = $options[self::OSS_UPLOAD_ID];
} else {
// initialize
$uploadId = $this->initiateMultipartUpload($bucket, $object, $options);
}
// generates the parts information and upload them one by one
$pieces = $this->generateMultiuploadParts($upload_file_size, (integer)$options[self::OSS_PART_SIZE]);
$response_upload_part = array();
foreach ($pieces as $i => $piece) {
$from_pos = $upload_position + (integer)$piece[self::OSS_SEEK_TO];
$to_pos = (integer)$piece[self::OSS_LENGTH] + $from_pos - 1;
$up_options = array(
self::OSS_FILE_UPLOAD => $uploadFile,
self::OSS_PART_NUM => ($i + 1),
self::OSS_SEEK_TO => $from_pos,
self::OSS_LENGTH => $to_pos - $from_pos + 1,
self::OSS_CHECK_MD5 => $is_check_md5,
);
if ($is_check_md5) {
$content_md5 = OssUtil::getMd5SumForFile($uploadFile, $from_pos, $to_pos);
$up_options[self::OSS_CONTENT_MD5] = $content_md5;
}
$response_upload_part[] = $this->uploadPart($bucket, $object, $uploadId, $up_options);
}
$uploadParts = array();
foreach ($response_upload_part as $i => $etag) {
$uploadParts[] = array(
'PartNumber' => ($i + 1),
'ETag' => $etag,
);
}
//build complete options
$cmp_options = null;
if (isset($options[self::OSS_HEADERS]) && isset($options[self::OSS_HEADERS][self::OSS_REQUEST_PAYER])) {
$cmp_options = array(
OssClient::OSS_HEADERS => array(
OssClient::OSS_REQUEST_PAYER => $options[self::OSS_HEADERS][self::OSS_REQUEST_PAYER],
));
}
return $this->completeMultipartUpload($bucket, $object, $uploadId, $uploadParts, $cmp_options);
}