Azure PHP SDK:按资产名称获取资产

时间:2015-07-10 13:16:07

标签: php azure sdk azure-storage-blobs

是否可以使用Azure PHP sdk使用资产名称获取资产详细信息。我可以获得所有资产清单,但它只加载前1000个资产。

getAssetList();

我可以使用资产ID获取单个资产详细信息。

getAsset($asset);

但在我的情况下,我没有资产ID。我只有资产名称。现在如何使用此获取资产详细信息?

编辑:

我从Azure支持部门得到了一些帮助,说我们可以使用$ skip参数进行分页。我在c#

中获得了代码段
for (int i = 0; i < _context.Assets.Count(); i += 1000 )
{
    var assets = _context.Assets.Skip(i);
    foreach (IAsset objIAsset in assets)
    {
        Console.WriteLine(objIAsset.Name.ToString());
    }
}

如何在PHP SDK中使用此参数。

4 个答案:

答案 0 :(得分:1)

似乎Azure SDK for PHP不支持跳过方法。但是,我使用fiddler来监视C#skip方法并得到如下URL:

https://***-hs.cloudapp.net/api/Assets()?$skip=1000

所以我认为我们可以在我们的PHP项目中加强上面的请求路径,我们可以修改&#34; getAssetList&#34;中的MediaServicesRestProxy方法。文件。

我添加了一个名为&#34; getAssetListBySkip($number)&#34;的函数进入&#34; MediaServicesRestProxy&#34; class,代码如下:

/**
 * Get asset list using skip number
 * 
 * */
public function getAssetListBySkip($number)
{
    $propertyList = $this->_getEntityList("Assets()?".'$skip='.$number);
    $result       = array();

    foreach ($propertyList as $properties) {
        $result[] = Asset::createFromOptions($properties);
    }

    return $result;
}

我们可以这样称呼这个方法:

$mediaServiceProxy = ServicesBuilder::getInstance()->createMediaServicesService(
        new MediaServicesSettings("**","**/**="));
$result=$mediaServiceProxy->getAssetListBySkip(1000);

答案 1 :(得分:1)

Azure Media服务支持按名称进行过滤。您可以将Web请求构建为

/api/assets()?$filter=Name%20eq%20'Your Name'&$top=1 

您还可以按其他属性进行过滤

答案 2 :(得分:0)

您是否尝试过在创建,处理,管理和交付资产时使用的REST API。 https://msdn.microsoft.com/en-us/library/azure/hh974277.aspx#list_an_asset但我认为我们可以直接通过名称列出资产,因为id是asset entity的唯一标识符。 PHP Azure SDK利用assetId获取资产:

 public function getAsset($asset) 
     { 
         $assetId = Utilities::getEntityId( 
           $asset, 
             'WindowsAzure\MediaServices\Models\Asset' 
        ); 

         return Asset::createFromOptions($this->_getEntity("Assets('{$assetId}')")); 
     } 
  

但在我的情况下,我没有资产ID。我只有资产名称   单独。现在如何使用此获取资产详细信息?

以下是一些测试功能代码片段供您参考:

public function testListAllAssets(){ 
           // 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->createAsset($asset1); 
         $asset2 = $this->createAsset($asset2); 
         $result = $this->restProxy->getAssetList(); 

         // Assert 
         $this->assertCount(2, $result); 
         $names = array( 
             $result[0]->getName(), 
             $result[1]->getName() 
         ); 
         $id = array( 
                 $result[0]->getId(), 
                 $result[1]->getId() 
         ); 
         $this->assertContains($asset1->getName(), $names); 
         $this->assertContains($asset2->getName(), $names); 

         $this->assertContains($asset1->getId(), $id); 
         $this->assertContains($asset2->getId(), $id); 
     } 

 public function testGetAnAssetReference(){ 

         // Setup 
         $assetName = TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix(); 
         $asset = new Asset(Asset::OPTIONS_NONE); 
         $asset->setName($assetName); 
         $asset = $this->createAsset($asset); 

         // Test 
         $result = $this->restProxy->getAsset($asset); 

         // Assert 
         $this->assertEquals($asset->getId(), $result->getId()); 
         $this->assertEquals($asset->getName(), $result->getName()); 
     } 

来自:https://github.com/Azure/azure-sdk-for-php/blob/master/tests/functional/WindowsAzure/MediaServices/MediaServicesFunctionalTest.php

答案 3 :(得分:0)

根据我的测试,似乎我们不能使用资产的名称来获取媒体服务中的资产信息。

$mediaServiceProxy = ServicesBuilder::getInstance()->createMediaServicesService(
              new MediaServicesSettings("**","******"));
$asset = new Asset(Asset::OPTIONS_NONE);
$asset->setName('For-Test-wmv-Source');
//$asset don't have the value of id,
// unless execute ‘createAsset($asset)’, "$asset1" will be set the ID 
$asset1 =$mediaServiceProxy->createAsset($asset);
$result2=$mediaServiceProxy->getAsset($asset1); 

PHP SDK支持名为“getAsset($ asset)”的方法。实际上,该方法按资产ID获取资产信息,就像Aka's reference code一样。而Azure REST API不支持Asset名称查询的方法。 请参阅official document

替代方法是,当您将资源信息(例如Id,URl,名称等)存储到媒体服务中时,可以将其存储到Azure table storage。如果您想使用它,可以从table storage获取和过滤您想要的资产名称数据。

相关问题