public function testMultipartUploadX() { // superfile size is over 1M $file_size = 20 * 1024 * 1024 + 317; $this->client->createBucket($this->bucket); $this->prepareTemporaryFile($file_size); $response = $this->client->initiateMultipartUpload($this->bucket, $this->key); $upload_id = $response['body']['uploadId']; $left_size = filesize($this->filename); $offset = 0; $part_number = 1; $part_list = array(); $etags = ''; while ($left_size > 0) { $part_size = min(BosClient::MIN_PART_SIZE, $left_size); $response = $this->client->uploadPartFromFile($this->bucket, $this->key, $upload_id, $part_number, $part_size, $this->filename, $offset); $this->checkProperties($response); $this->assertEquals(0, $response['http_headers']['content-length']); $part_list[] = array('partNumber' => $part_number, 'eTag' => $response['http_headers']['etag']); $etags .= $response['http_headers']['etag']; $left_size -= $part_size; $offset += $part_size; $part_number += 1; } $response = $this->client->completeMultipartUpload($this->bucket, $this->key, $upload_id, $part_list); $this->checkProperties($response); $this->assertArrayHasKey('location', $response['body']); $this->assertEquals($this->bucket, $response['body']['bucket']); $this->assertEquals($this->key, $response['body']['key']); $this->assertEquals('-' . md5($etags), $response['body']['eTag']); $response = $this->client->getObjectMetadata($this->bucket, $this->key); $this->checkProperties($response); $this->assertEquals($file_size, $response['http_headers']['content-length']); $this->assertEquals(Coder::guessMimeType($this->key), $response['http_headers']['content-type']); $this->assertEquals('-' . md5($etags), $response['http_headers']['etag']); }
/** * Initialize multi_upload_file. * * @param string $bucket_name The bucket name. * @param string $key The object path. * @param mixed $config The optional bce configuration, which will overwrite the * default configuration that was passed while creating BosClient instance. * * @return mixed */ public function initiateMultipartUpload($bucket_name, $key, $config = array()) { $content_type = Coder::guessMimeType($key); $headers = array(HttpHeaders::CONTENT_TYPE => $content_type); return $this->sendRequest(HttpMethod::POST, array('bucket_name' => $bucket_name, 'key' => $key, 'params' => array('uploads' => ''), 'headers' => $headers, 'config' => $config)); }