2015-07-10 45 views
2

是否可以使用Azure PHP sdk的資產名稱獲取資產詳細信息?我可以獲得所有資產列表,但它只會加載前1000個資產。Azure PHP SDK:按資產名稱獲取資產

getAssetList(); 

我可以使用資產ID獲取單個資產詳細信息。

getAsset($asset); 

但在我的情況下,我沒有資產ID與我。我只有資產名稱。現在我如何使用這個獲得資產細節?

編輯:

我從Azure支持一些幫助說,我們可以用$跳過參數分頁。我在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中使用此參數。

回答

1

Azure SDK for PHP似乎不支持skip方法。但是,我用小提琴手監控C#skip方法,得到了這樣的網址:

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

所以我認爲我們可以在我們的PHP項目上面bulid了請求路徑一樣,我們可以在修改getAssetList法「 MediaServicesRestProxy「文件。

我添加一個名爲 「getAssetListBySkip($number)」 功能爲 「MediaServicesRestProxy」 類中,這樣的代碼:

/** 
* 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); 
+0

這很完美。非常感謝 :) –

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

+0

過濾這個方法我試過,但是當我嘗試創建新的資產與創建同名的新容器中。在這種情況下,我無法獲得已經創建的容器SAS網址。 –

+0

這是可能提供您的文章中的代碼片段,讓我們重現您的問題[創建具有相同名稱的新容器創建新的資產。]方便嗎?目前,我無法完全理解你的根本原因。 – 2015-07-13 17:32:46

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不支持按資產名稱查詢的方法。 請參考official document

另一種方法是,當您將資產信息上傳到媒體服務時,您可以將其資產信息(如Id,URl,名稱等)存儲到Azure table storage中。如果您想使用它,您可以從table storage中獲取並過濾您想要的資產名稱的數據。

+0

是的,我可以將其存儲以備將來使用。但不幸的是我錯過了他們的存儲。所以現在我擁有2000多個資產。有沒有其他的工作來完成這件事? –

+0

正如我在我的問題編輯中提到的,我從Azure支持獲得了一些幫助,使用$ skip進行分頁。但我找不到任何PHP文檔。 –

1

Azure的媒體服務支持篩選按名字。您可以構建web請求要像

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

您還可以通過其他屬性