public function testUploadLargeFileFromResource() { // Setup $assetName = TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix(); $assetOptions = Asset::OPTIONS_NONE; $accessPolicyName = TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix(); $accessPolicyNameRead = TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix(); $accessPolicyDuration = 30; $accessPolicyDurationRead = 300; $accessPolicyPermission = AccessPolicy::PERMISSIONS_WRITE; $accessPolicyPermissionRead = AccessPolicy::PERMISSIONS_READ; $locatorStartTime = new \DateTime('now -5 minutes'); $locatorType = Locator::TYPE_SAS; $locatorStartTimeRead = new \DateTime('now -5 minutes'); $locatorTypeRead = Locator::TYPE_SAS; $fileName = TestResources::MEDIA_SERVICES_DUMMY_FILE_NAME; $fileContent = $this->createLargeFile(); $resource = fopen(VirtualFileSystem::newFile($fileContent), 'r'); // Test $asset = new Asset($assetOptions); $asset->setName($assetName); $asset = $this->createAsset($asset); $access = new AccessPolicy($accessPolicyName); $access->setDurationInMinutes($accessPolicyDuration); $access->setPermissions($accessPolicyPermission); $access = $this->createAccessPolicy($access); $locator = new Locator($asset, $access, $locatorType); $locator->setStartTime($locatorStartTime); $locator = $this->createLocator($locator); $this->restProxy->uploadAssetFile($locator, $fileName, $resource); $this->restProxy->createFileInfos($asset); $assetFiles = $this->restProxy->getAssetFileList(); $accessRead = new AccessPolicy($accessPolicyNameRead); $accessRead->setDurationInMinutes($accessPolicyDurationRead); $accessRead->setPermissions($accessPolicyPermissionRead); $accessRead = $this->createAccessPolicy($accessRead); $locatorRead = new Locator($asset, $accessRead, $locatorTypeRead); $locatorRead->setStartTime($locatorStartTimeRead); $locatorRead = $this->createLocator($locatorRead); // without sleep() Locator hasn't enough time to create URL, so that's why we have to use at least sleep(30) sleep(40); $method = Resources::HTTP_GET; $url = new Url($locatorRead->getBaseUri() . '/' . $fileName . $locatorRead->getContentAccessComponent()); $filters = array(); $statusCode = Resources::STATUS_OK; $httpClient = new HttpClient(); $httpClient->setMethod($method); $httpClient->setExpectedStatusCode($statusCode); $downloadedFileContent = $httpClient->send($filters, $url); // Assert $this->assertEquals($assetName, $asset->getName()); $this->assertEquals($assetOptions, $asset->getOptions()); $this->assertNotNull($asset->getId()); $this->assertNotNull($asset->getCreated()); $this->assertEquals($accessPolicyName, $access->getName()); $this->assertEquals($accessPolicyDuration, $access->getDurationInMinutes()); $this->assertEquals($accessPolicyPermission, $access->getPermissions()); $this->assertEquals($accessPolicyNameRead, $accessRead->getName()); $this->assertEquals($accessPolicyDurationRead, $accessRead->getDurationInMinutes()); $this->assertEquals($accessPolicyPermissionRead, $accessRead->getPermissions()); $this->assertNotNull($asset->getId()); $this->assertNotNull($asset->getCreated()); $this->assertEquals($locatorType, $locator->getType()); $this->assertEquals($locatorStartTime->getTimestamp(), $locator->getStartTime()->getTimestamp()); $this->assertEquals($locatorTypeRead, $locatorRead->getType()); $this->assertEquals($locatorStartTimeRead->getTimestamp(), $locatorRead->getStartTime()->getTimestamp()); $this->assertEquals($asset->getId(), $locator->getAssetId()); $this->assertEquals($access->getId(), $locator->getAccessPolicyId()); $this->assertEquals($asset->getId(), $locatorRead->getAssetId()); $this->assertEquals($accessRead->getId(), $locatorRead->getAccessPolicyId()); $this->assertEquals(1, count($assetFiles)); $this->assertEquals($asset->getId(), $assetFiles[0]->getParentAssetId()); $this->assertEquals($fileName, $assetFiles[0]->getName()); $this->assertEquals($fileContent, $downloadedFileContent); }
private function _commitBlocks($url, $blockIds) { $baseUrl = new Url($url); $baseUrl->setQueryVariable(Resources::QP_COMP, 'blocklist'); $xml = new \XMLWriter(); $xml->openMemory(); $xml->setIndent(true); $xml->startDocument('1.0', 'UTF-8'); $xml->startElement('BlockList'); foreach ($blockIds as $blockId) { $xml->writeElement('Latest', $blockId); } $xml->endElement(); $xml->endDocument(); $xmlContent = $xml->outputMemory(); $method = Resources::HTTP_PUT; $filters = array(); $statusCode = Resources::STATUS_CREATED; $headers = array(Resources::CONTENT_TYPE => Resources::BINARY_FILE_TYPE, Resources::X_MS_VERSION => Resources::STORAGE_API_LATEST_VERSION); $httpClient = new HttpClient(); $httpClient->setMethod($method); $httpClient->setHeaders($headers); $httpClient->setExpectedStatusCode($statusCode); $httpClient->setBody($xmlContent); $httpClient->send($filters, $baseUrl); }
/** * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createAsset * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createAccessPolicy * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createLocator */ public function testCreatingOriginUrlForStreamingContent() { // Setup $asset = $this->createAssetWithFilesForStream(); $accessPolicy = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix()); $accessPolicy->setDurationInMinutes(300); $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_READ); $accessPolicy = $this->createAccessPolicy($accessPolicy); $locator = new Locator($asset, $accessPolicy, Locator::TYPE_ON_DEMAND_ORIGIN); $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix()); $locator->setStartTime(new \DateTime('now -5 minutes')); $locator = $this->createLocator($locator); $expectedFileContent = TestResources::getSmallIsmc(); // without sleep() Locator hasn't enough time to create URL, so that's why we have to use at least sleep(30) sleep(40); // Test $method = Resources::HTTP_GET; $url = new Url($locator->getPath() . '/' . TestResources::MEDIA_SERVICES_ISM_FILE_NAME . '/' . TestResources::MEDIA_SERVICES_STREAM_APPEND); $filters = array(); $statusCode = Resources::STATUS_OK; $httpClient = new HttpClient(); $httpClient->setMethod($method); $httpClient->setExpectedStatusCode($statusCode); $result = $httpClient->send($filters, $url); // Assert $this->assertEquals($expectedFileContent, $result); }
/** * @covers WindowsAzure\Common\Internal\Http\HttpClient::getResponse */ public function testGetResponse() { // Setup $channel = new HttpClient(); $url = new Url('http://www.microsoft.com/'); $channel->setExpectedStatusCode('200'); $channel->send(array(), $url); // Test $response = $channel->getResponse(); // Assert $this->assertInstanceOf('\\HTTP_Request2_Response', $response); }
public function uploadFile($fileName, $fileContent) { $asset = new Asset(Asset::OPTIONS_NONE); $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix()); $asset = $this->createAsset($asset); $access = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix()); $access->setDurationInMinutes(30); $access->setPermissions(AccessPolicy::PERMISSIONS_WRITE); $access = $this->createAccessPolicy($access); $locator = new Locator($asset, $access, Locator::TYPE_SAS); $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix()); $locator->setStartTime(new \DateTime('now -5 minutes')); $locator = $this->createLocator($locator); $this->restProxy->uploadAssetFile($locator, $fileName, $fileContent); $this->restProxy->createFileInfos($asset); $accessPolicy = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix()); $accessPolicy->setDurationInMinutes(300); $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_READ); $accessPolicy = $this->createAccessPolicy($accessPolicy); $locator = new Locator($asset, $accessPolicy, Locator::TYPE_SAS); $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix()); $locator->setStartTime(new \DateTime('now -5 minutes')); $locator = $this->createLocator($locator); // without sleep() Locator hasn't enough time to create URL, so that's why we have to use at least sleep(30) sleep(40); $method = Resources::HTTP_GET; $url = new Url($locator->getBaseUri() . '/' . $fileName . $locator->getContentAccessComponent()); $filters = array(); $statusCode = Resources::STATUS_OK; $httpClient = new HttpClient(); $httpClient->setMethod($method); $httpClient->setExpectedStatusCode($statusCode); return $httpClient->send($filters, $url); }
/** * Upload asset file to storage. * * @param WindowsAzure\MediaServices\Models\Locator $locator Write locator for * file upload * * @param string $name Uploading filename * @param string $body Uploading content * * @return none */ public function uploadAssetFile($locator, $name, $body) { Validate::isA($locator, 'WindowsAzure\\Mediaservices\\Models\\Locator', 'locator'); Validate::isString($name, 'name'); Validate::notNull($body, 'body'); $method = Resources::HTTP_PUT; $urlFile = $locator->getBaseUri() . '/' . $name; $url = new Url($urlFile . $locator->getContentAccessComponent()); $filters = array(); $statusCode = Resources::STATUS_CREATED; $headers = array(Resources::CONTENT_TYPE => Resources::BINARY_FILE_TYPE, Resources::X_MS_VERSION => Resources::STORAGE_API_LATEST_VERSION, Resources::X_MS_BLOB_TYPE => BlobType::BLOCK_BLOB); $httpClient = new HttpClient(); $httpClient->setMethod($method); $httpClient->setHeaders($headers); $httpClient->setExpectedStatusCode($statusCode); $httpClient->setBody($body); $httpClient->send($filters, $url); }