Azure PHP SDK:通过资产名称获取资产

Azure PHP SDK: get the asset by asset name

是否可以通过 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 中使用此参数。

您是否尝试过在创建、处理、管理和交付资产时使用的 REST API。 https://msdn.microsoft.com/en-us/library/azure/hh974277.aspx#list_an_asset but I do think we can list asset via a name directly since id is an unique indentifier of 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}')")); 
     } 

But in my case, I don't have asset id with me. I just have asset name alone. Now how do I get the asset details using this?

这里有一些测试功能代码片段供大家参考:

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

根据我的测试,似乎不能通过Asset的名字来获取Media Service中的asset信息。

$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)”的方法。实际上,该方法通过Asset id 获取Asset 信息,就像Aka's reference code 一样。而Azure REST API 不支持通过Asset 名称查询的方法。 请参考official document.

另一种方法是,当您将资产信息(例如 Id、URl、名称等)上传到媒体服务时,您可以将它们存储到 Azure table storage 中。如果你想使用它,你可以从 table storage.

中获取并过滤你想要的 Asset 名称的数据

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

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

所以我认为我们可以在我们的PHP项目中像上面那样构建请求路径,我们可以修改“MediaServicesRestProxy”文件中的getAssetList方法。

我将名为“getAssetListBySkip($number)”的函数添加到“MediaServicesRestProxy”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);

Azure 媒体服务支持按名称筛选。您可以将 Web 请求构造为

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

您还可以按其他属性筛选