function multipartUpload($client, $bucket, $keyprefix) { //初始化分开上传,获取uploadid $args = array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile"); $uploadid = $client->initMultipartUpload($args); $uploadid = $uploadid["UploadId"]; //获取到uploadid //开始上传 $file = "D://IMG.jpg"; //要上传的文件 $partsize = 1024 * 100; $resource = fopen($file, "r"); $stat = fstat($resource); $total = $stat["size"]; //获取文件的总大小 fclose($resource); $count = (int) ($total / $partsize + 1); //计算文件需要分几块上传 for ($i = 0; $i < $count; $i++) { //依次上传每一块 echo "upload" . $i . "\r\n"; $args = array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile", "LastPart" => $i === $count - 1, "Options" => array("partNumber" => $i + 1, "uploadId" => $uploadid), "ObjectMeta" => array("Content-Length" => min($partsize, $total - $partsize * $i)), "Content" => array("content" => $file, "seek_position" => $partsize * $i)); $etag = $client->uploadPart($args); $etag = $etag["ETag"]; } $parts = $client->listParts(array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile", "Options" => array("uploadId" => $uploadid))); //结束上传 $args = array("Bucket" => $bucket, "Key" => $keyprefix . "EOFile", "Options" => array("uploadId" => $uploadid), "Parts" => $parts["Parts"]); $result = $client->completeMultipartUpload($args); rangeGetAndCheckMd5($client, $bucket, $keyprefix . "EOFile", "D://testdown/down", base64_encode(md5_file("D://IMG.jpg"))); }
public function testMultipartUploadUsingEncyptionMeta() { generateFile(1024 * 1024, $this->cachedir . "multi"); //初始化分开上传,获取uploadid $args = array("Bucket" => $this->bucket, "Key" => $this->key); $uploadid = $this->encryptionClient->initMultipartUpload($args); $uploadid = $uploadid["UploadId"]; //获取到uploadid //开始上传 $file = $this->cachedir . "multi"; //要上传的文件 $partsize = 1024 * 100; $resource = fopen($file, "r"); $stat = fstat($resource); $total = $stat["size"]; //获取文件的总大小 fclose($resource); $count = (int) ($total / $partsize + 1); //计算文件需要分几块上传 for ($i = 0; $i < $count; $i++) { //依次上传每一块 echo "upload" . $i . "\r\n"; $args = array("Bucket" => $this->bucket, "Key" => $this->key, "LastPart" => $i === $count - 1, "Options" => array("partNumber" => $i + 1, "uploadId" => $uploadid), "ObjectMeta" => array("Content-Length" => min($partsize, $total - $partsize * $i)), "Content" => array("content" => $file, "seek_position" => $partsize * $i)); $etag = $this->encryptionClient->uploadPart($args); $etag = $etag["ETag"]; } $parts = $this->encryptionClient->listParts(array("Bucket" => $this->bucket, "Key" => $this->key, "Options" => array("uploadId" => $uploadid))); //结束上传 $args = array("Bucket" => $this->bucket, "Key" => $this->key, "Options" => array("uploadId" => $uploadid), "Parts" => $parts["Parts"]); $result = $this->encryptionClient->completeMultipartUpload($args); rangeGetAndCheckMd5($this->encryptionClient, $this->bucket, $this->key, $this->cachedir . "down", md5_file($file)); @unlink($this->cachedir . "multi"); }