function uploadFileAndCreateAsset($restProxy, $mezzanineFileName) { // 1.1. create an empty "Asset" by specifying the name $asset = new Asset(Asset::OPTIONS_NONE); $asset->setName("Mezzanine " . $mezzanineFileName); $asset = $restProxy->createAsset($asset); $assetId = $asset->getId(); print "Asset created: name=" . $asset->getName() . " id=" . $assetId . "\r\n"; // 1.3. create an Access Policy with Write permissions $accessPolicy = new AccessPolicy('UploadAccessPolicy'); $accessPolicy->setDurationInMinutes(60.0); $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_WRITE); $accessPolicy = $restProxy->createAccessPolicy($accessPolicy); // 1.4. create a SAS Locator for the Asset $sasLocator = new Locator($asset, $accessPolicy, Locator::TYPE_SAS); $sasLocator->setStartTime(new \DateTime('now -5 minutes')); $sasLocator = $restProxy->createLocator($sasLocator); // 1.5. get the mezzanine file content $fileContent = file_get_contents($mezzanineFileName); print "Uploading...\r\n"; // 1.6. use the 'uploadAssetFile' to perform a multi-part upload using the Block Blobs REST API storage operations $restProxy->uploadAssetFile($sasLocator, $mezzanineFileName, $fileContent); // 1.7. notify Media Services that the file upload operation is done to generate the asset file metadata $restProxy->createFileInfos($asset); print "File uploaded: size=" . strlen($fileContent) . "\r\n"; // 1.8. delete the SAS Locator (and Access Policy) for the Asset since we are done uploading files $restProxy->deleteLocator($sasLocator); $restProxy->deleteAccessPolicy($accessPolicy); return $asset; }
/** * Get job output assets. * * @param WindowsAzure\MediaServices\Models\Job|string $job Job data or job Id * * @return array of Models\Asset */ public function getJobOutputMediaAssets($job) { $jobId = Utilities::getEntityId($job, 'WindowsAzure\\Mediaservices\\Models\\Job'); $propertyList = $this->_getEntityList("Jobs('{$jobId}')/OutputMediaAssets"); $result = array(); foreach ($propertyList as $properties) { $result[] = Asset::createFromOptions($properties); } return $result; }
private function makeProgram($name, $channel) { $asset = new Asset(Asset::OPTIONS_NONE); $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix()); $asset = $this->createAsset($asset); $policy = new AssetDeliveryPolicy(); $policy->setName("Clear Policy"); $policy->setAssetDeliveryProtocol(AssetDeliveryProtocol::SMOOTH_STREAMING | AssetDeliveryProtocol::DASH | AssetDeliveryProtocol::HLS); $policy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::NO_DYNAMIC_ENCRYPTION); $policy = $this->createAssetDeliveryPolicy($policy); $this->restProxy->linkDeliveryPolicyToAsset($asset, $policy); $program = new Program(); $program->setName($name); $program->setAssetId($asset->getId()); $program->setArchiveWindowLength(new \DateInterval("PT1H")); $program->setChannelId($channel->getId()); return $program; }
/** * @covers WindowsAzure\Common\Internal\Utilities::getEntityId */ public function testGetEntityIdWithObject() { // Setup $idKey = 'Id'; $optionKey = 'Options'; $assetArray = array($idKey => 'kjgdfg57', $optionKey => Asset::OPTIONS_NONE); $value = Asset::createFromOptions($assetArray); // Test $result = Utilities::GetEntityId($value, 'WindowsAzure\\MediaServices\\Models\\Asset'); //Assert $this->assertEquals($assetArray[$idKey], $result); }
private function addAsset($assetName) { $assetOptions = Asset::OPTIONS_NONE; $asset = new Asset($assetOptions); $asset->setName($assetName); $asset = $this->_mediaServiceProxy->createAsset($asset); return $asset; }
/** * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::updateLocator */ public function testUpdateLocator() { // Setup $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_READ + AccessPolicy::PERMISSIONS_LIST); $access = $this->createAccessPolicy($access); $locator = new Locator($asset, $access, Locator::TYPE_ON_DEMAND_ORIGIN); $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix()); $locator = $this->createLocator($locator); $newName = TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix(); // Test $locator->setName($newName); $this->restProxy->updateLocator($locator); // Assert $this->assertEquals($newName, $locator->getName()); }
/** * Create asset from array * * @param array $options Array containing values for object properties * * @return WindowsAzure\MediaServices\Models\Asset */ public static function createFromOptions($options) { Validate::notNull($options['Options'], 'options[Options]'); $asset = new Asset($options['Options']); $asset->fromArray($options); return $asset; }
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); }
/** * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::createAsset * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::getAssetList * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::deleteAsset */ public function testDeleteAsset() { // Setup $asset1 = new Asset(Asset::OPTIONS_NONE); $asset1->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix()); $asset2 = new Asset(Asset::OPTIONS_NONE); $asset2->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix()); // Test $asset1 = $this->restProxy->createAsset($asset1); $asset2 = $this->restProxy->createAsset($asset2); $result = $this->restProxy->getAssetList(); $before = count($result); foreach ($result as $res) { $this->restProxy->deleteAsset($res); } $after = count($this->restProxy->getAssetList()); // Assert $this->assertEquals(2, $before); $this->assertEquals(0, $after); }
/** * @covers WindowsAzure\MediaServices\Models\Asset::createFromOptions * @covers WindowsAzure\MediaServices\Models\Asset::fromArray */ public function testAssetFromOptions() { // Setup $assetArray = array('Id' => '1', 'State' => Asset::STATE_PUBLISHED, 'Created' => '2013-11-19', 'LastModified' => '2013-11-19', 'AlternateId' => '2', 'Name' => 'newName', 'Options' => Asset::OPTIONS_NONE, 'Uri' => 'http://en.wikipedia.org/wiki/Uniform_resource_locator', 'StorageAccountName' => 'StorageName'); $created = new \Datetime($assetArray['Created']); $modified = new \Datetime($assetArray['LastModified']); // Test $resultAsset = Asset::createFromOptions($assetArray); // Assert $this->assertEquals($assetArray['Id'], $resultAsset->getId()); $this->assertEquals($assetArray['State'], $resultAsset->getState()); $this->assertEquals($created, $resultAsset->getCreated()); $this->assertEquals($modified, $resultAsset->getLastModified()); $this->assertEquals($assetArray['AlternateId'], $resultAsset->getAlternateId()); $this->assertEquals($assetArray['Name'], $resultAsset->getName()); $this->assertEquals($assetArray['Options'], $resultAsset->getOptions()); $this->assertEquals($assetArray['Uri'], $resultAsset->getUri()); $this->assertEquals($assetArray['StorageAccountName'], $resultAsset->getStorageAccountName()); }
public function createAssetWithFilesForStream() { $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); $firstFile = TestResources::getSmallIsm(); $secondFile = TestResources::getSmallIsmc(); $this->restProxy->uploadAssetFile($locator, TestResources::MEDIA_SERVICES_ISM_FILE_NAME, $firstFile); $this->restProxy->uploadAssetFile($locator, TestResources::MEDIA_SERVICES_ISMC_FILE_NAME, $secondFile); $this->restProxy->createFileInfos($asset); return $asset; }
use WindowsAzure\MediaServices\Models\ContentKeyDeliveryType; use WindowsAzure\MediaServices\Models\ContentKeyRestrictionType; use WindowsAzure\MediaServices\Models\AssetDeliveryPolicy; use WindowsAzure\MediaServices\Models\AssetDeliveryProtocol; use WindowsAzure\MediaServices\Models\AssetDeliveryPolicyType; use WindowsAzure\MediaServices\Models\AssetDeliveryPolicyConfigurationKey; // Settings $account = "<your account here>"; $secret = "<account key here>"; $mezzanineFileName = "Azure-Video.wmv"; print "Azure SDK for PHP - AES Dynamic Encryption Sample\r\n"; // Phase 1 - Upload the mezzanine // 1.1. set up the MediaServicesService object to call into the Media Services REST API. $restProxy = ServicesBuilder::getInstance()->createMediaServicesService(new MediaServicesSettings($account, $secret)); // 1.2. create an empty "Asset" by specifying the name and Storage account to use $asset = new Asset(Asset::OPTIONS_NONE); $asset->setName("Mezzanine " . $mezzanineFileName); $asset = $restProxy->createAsset($asset); $assetId = $asset->getId(); print "Asset created: name=" . $asset->getName() . " id=" . $assetId . "\r\n"; // 1.3. create an Access Policy with Write permissions $accessPolicy = new AccessPolicy('UploadAccessPolicy'); $accessPolicy->setDurationInMinutes(60.0); $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_WRITE); $accessPolicy = $restProxy->createAccessPolicy($accessPolicy); // 1.4. create a SAS Locator for the Asset $sasLocator = new Locator($asset, $accessPolicy, Locator::TYPE_SAS); $sasLocator->setStartTime(new \DateTime('now -5 minutes')); $sasLocator = $restProxy->createLocator($sasLocator); // 1.5. get the mezzanine file content $fileContent = file_get_contents($mezzanineFileName);
public function uploadSingleFile($fileName, $fileContent) { $asset = new Asset(Asset::OPTIONS_NONE); $asset->setName($fileName); $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); $list = $this->restProxy->getAssetAssetFileList($asset); if (isset($list[0])) { $list[0]->setIsPrimary(true); $this->restProxy->updateAssetFile($list[0]); } else { throw new Exception("unable to find the asset file"); } return $asset; }
/** * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::removeContentKeyFromAsset */ public function testRemoveContentKeyFromAsset() { // Setup $aesKey = Utilities::generateCryptoKey(32); $protectionKeyId = $this->restProxy->getProtectionKeyId(ContentKeyTypes::COMMON_ENCRYPTION); $protectionKey = $this->restProxy->getProtectionKey($protectionKeyId); $contentKey = new ContentKey(); $contentKey->setContentKey($aesKey, $protectionKey); $contentKey->setProtectionKeyId($protectionKeyId); $contentKey->setProtectionKeyType(ProtectionKeyTypes::X509_CERTIFICATE_THUMBPRINT); $contentKey->setContentKeyType(ContentKeyTypes::COMMON_ENCRYPTION); $contentKey = $this->createContentKey($contentKey); $asset = new Asset(Asset::OPTIONS_COMMON_ENCRYPTION_PROTECTED); $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix()); $asset = $this->createAsset($asset); $this->restProxy->linkContentKeyToAsset($asset, $contentKey); // Test $this->restProxy->removeContentKeyFromAsset($asset, $contentKey); // Assert $contentKeyFromAsset = $this->restProxy->getAssetContentKeys($asset); $this->assertEmpty($contentKeyFromAsset); }
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); }
/** * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::removeDeliveryPolicyFromAsset */ public function testRemoveDeliveryPolicyFromAsset() { // Setup $asset = new Asset(Asset::OPTIONS_NONE); $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME + $this->createSuffix()); $asset = $this->createAsset($asset); $policyId = $this->testCreateAssetDeliveryPolicy(); $this->restProxy->linkDeliveryPolicyToAsset($asset, $policyId); // Test $this->restProxy->removeDeliveryPolicyFromAsset($asset, $policyId); // Assert $optionsFromPolicy = $this->restProxy->getAssetLinkedDeliveryPolicy($asset); $this->assertEmpty($optionsFromPolicy); }
/** * @covers WindowsAzure\MediaServices\Internal\ContentPropertiesSerializer::serialize * @covers WindowsAzure\MediaServices\Internal\ContentPropertiesSerializer::_serializeRecursive */ public function testSerializeDate() { // Setup $name = 'NameName'; $nameKey = 'Name'; $optionsKey = 'Options'; $option = Asset::OPTIONS_STORAGE_ENCRYPTED; $dateKey = 'Created'; $date = '2013-12-31T01:16:25+01:00'; $assetArray = array($nameKey => $name, $optionsKey => $option, $dateKey => $date); $asset = Asset::createFromOptions($assetArray); $expected = ' <meta:properties xmlns:meta="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <data:' . $optionsKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $option . '</data:' . $optionsKey . '> <data:' . $nameKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $name . '</data:' . $nameKey . '> <data:' . $dateKey . ' xmlns:data="http://schemas.microsoft.com/ado/2007/08/dataservices">' . $date . '</data:' . $dateKey . '> </meta:properties> '; // Test $result = ContentPropertiesSerializer::serialize($asset); // Assert $this->assertXmlStringEqualsXmlString($expected, $result); }
/** * @covers WindowsAzure\MediaServices\Models\ContentProperties::writeInnerXml */ public function testWriteInnerXml() { // Setup $name = 'Name'; $option = Asset::OPTIONS_NONE; $asset = new Asset($option); $asset->setName($name); $asset->setOptions(Asset::OPTIONS_STORAGE_ENCRYPTED); $prop = new ContentProperties(); $prop->setPropertiesFromObject($asset); // Test $xmlWriter = new \XMLWriter(); $xmlWriter->openMemory(); $prop->writeInnerXml($xmlWriter); $result = $xmlWriter->outputMemory(); // Assert $this->assertContains(':Options', $result); $this->assertContains(':Name', $result); }