匯出 (0) 列印
全部展開

使用 Media Services REST API 擷取資產

更新日期: 2014年8月

使用 REST API 將資產擷取到 Microsoft Azure Media Services 中牽涉到許多步驟。對於某些動作 (例如將資產加密),您必須先執行許多步驟,才能與 媒體服務 互動。然而,大部分的動作 (例如建立資產本身) 都很直接,您只需要有 REST 原則、OData v3 及 (在程式碼範例的情況中) JSON 的基本知識即可。

擷取資產的基本工作流程將於下列幾節中討論:

如需大量擷取資產的相關資訊,請參閱使用 REST API 大量擷取資產

note附註
媒體服務在建置串流內容的 URL 時使用 IAssetFile.Name 屬性值 (例如,http://{WAMSAccount}.origin.mediaservices.windows.net/{GUID}/{IAssetFile.Name}/streamingParameters)。因此,不允許百分比編碼。名稱屬性的值沒有以下任何保留的百分比編碼字元:!*'();:@&=+$,/?%#[]"。檔案副檔名只能有一個 ‘.’。

Important重要事項
使用媒體服務 REST API 時,適用下列考量:

資產是多種類型或多組 媒體服務 物件的容器,包括視訊、音訊、影像、縮圖集合、文字播放軌及隱藏式輔助字幕檔案的容器。在 REST API 中,建立資產必須傳送 POST 要求到 媒體服務,並將關於資產的任何屬性資訊放在要求本文中。

下列範例顯示如何使用好記的名稱「NewJSONAsset」來建立資產。

POST https://media.windows.net/API/Assets HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1335602357&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=XQs5T%2fEfdO39%2f0Z9%2fBBkA12%2bbUUEY21YyefWXuRYZlY%3d
Host: media.windows.net
Content-Length: 27
Expect: 100-continue

{ "Name" : "NewJSONAsset" }

如果成功,會傳回以下回應:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 1353
Content-Type: application/json;odata=verbose;charset=utf-8
Location: https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')
Server: Microsoft-IIS/7.5
x-ms-request-id: 7739638a-da3a-4a6e-ad51-ea0bf87f02ad
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 27 Apr 2012 22:39:18 GMT

{"d":{"__metadata":{"id":"https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')","uri":"https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')","type":"Microsoft.Cloud.Media.Vod.Rest.Data.Models.Asset","actions":{"https://media.windows.net/api/$metadata#WindowsAzureMediaServices.Publish":[{"title":"Publish","target":"https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')/Publish"}]}},"Locators":{"__deferred":{"uri":"https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')/Locators"}},"ContentKeys":{"__deferred":{"uri":"https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')/ContentKeys"}},"Files":{"__deferred":{"uri":"https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')/Files"}},"ParentAssets":{"__deferred":{"uri":"https://media.windows.net/api/Assets('nb%3Acid%3AUUID%3Aaa5bfdd9-900a-431d-aea7-fffb0b24f36b')/ParentAssets"}},"Id":"nb:cid:UUID:aa5bfdd9-900a-431d-aea7-fffb0b24f36b","State":0,"Created":"\/Date(1335566358610)\/","LastModified":"\/Date(1335566358610)\/","AlternateId":null,"Name":"NewJSONAsset","Options":0}}

如需 Asset 實體屬性與作業的詳細資訊,請參閱資產

資產加密是選用步驟。不過,建議您可以加密資產。在 媒體服務 中,您可以使用:用來管理受 DRM 保護的檔案之資產檔案的儲存體加密或一般加密 (例如 PlayReady)。您也可以使用組態加密來加密可能包含敏感預設資訊的編碼設定資料。每種類型的加密都需要 AES 內容金鑰、用來將內容金鑰加密的 X.509 憑證,以及在 Asset、ContentKey 和 File 實體上設定對應的屬性。內容金鑰的長度會依內容金鑰的類型而異。儲存體與組態加密需要 256 位元的金鑰,而一般加密需要 128 位元的金鑰。

以下是將您上傳到 Blob儲存體的檔案加密的一般步驟:

  1. 隨機產生 256 位元 (32 個位元組) 的 AES 金鑰。這是您資產的內容金鑰,表示與該資產相關的所有檔案在解密時都必須使用同內容金鑰。

  2. 隨機為每個檔案產生 64 位元的初始化向量 (IV) 值,確定資產中每個檔案的 IV 值都是唯一值。

  3. 如果您想要在上傳 (擷取) 之後再加密資產檔案,將選項屬性設為 "1" 以建立資產實體。若您使用一般加密,設定選項為 "2"。

    note附註
    此步驟可以在執行步驟 1 與 2 之前或之後執行。

  4. 呼叫 GetProtectionKeyId 與 GetProtectionKey 方法,以取得將內容金鑰加密所需的正確 X.509 憑證。

  5. 使用 X.509 憑證的公開金鑰將內容金鑰加密。

    同時也請建立使用金鑰識別碼和內容金鑰計算的總和檢查碼值 (根據 PlayReady AES 金鑰總和檢查碼演算法)。如需詳細資訊,請參閱 PlayReady 標頭物件文件的「PlayReady AES 金鑰總和檢查碼演算法」一節 (位於此處)。

    下列 .NET 範例將使用金鑰識別碼和明文內容金鑰的 GUID 部分計算總和檢查碼。

    public static string CalculateChecksum(byte[] contentKey, Guid keyId)
    {
        byte[] array = null;
        using (AesCryptoServiceProvider aesCryptoServiceProvider = new AesCryptoServiceProvider())
        {
            aesCryptoServiceProvider.Mode = CipherMode.ECB;
            aesCryptoServiceProvider.Key = contentKey;
            aesCryptoServiceProvider.Padding = PaddingMode.None;
            ICryptoTransform cryptoTransform = aesCryptoServiceProvider.CreateEncryptor();
            array = new byte[16];
            cryptoTransform.TransformBlock(keyId.ToByteArray(), 0, 16, array, 0);
        }
        byte[] array2 = new byte[8];
        Array.Copy(array, array2, 8);
        return Convert.ToBase64String(array2);
    }
    
  6. 建立 ContentKey 實體,並使用您在前面步驟得到的值設定 EncryptedContentKey (轉換為 base64 編碼字串)、ProtectionKeyId、ProtectionKeyType、ContentKeyType 及 Checksum 屬性。

  7. 透過 $links 作業將 ContentKey 實體與 Asset 實體產生關聯。

  8. 上傳檔案 (細節將於下一節說明) 之後,呼叫 CreateFileInfos 並使用前幾個步驟建立的值更新 File 實體的加密屬性。

Important重要事項
本主題已省略定義加密金鑰的範例。只提供示範如何與 Media Services 互動的範例。

下列範例示範如何針對內容金鑰加密時必須使用的憑證,擷取憑證指紋 ProtectionKeyId。執行此步驟,以確定電腦上已經有適當的憑證。

GET https://media.windows.net/API/GetProtectionKeyId?contentKeyType=1 HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1335862109&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=ErOpftkPKjzX3bdYcEUZTK9yAwKIDc20y0kxEBZLvCk%3d
Host: media.windows.net

如果成功,會傳回以下回應:

HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 71
Content-Type: application/json;odata=verbose;charset=utf-8
Server: Microsoft-IIS/7.5
x-ms-request-id: 7940b777-4c95-4c68-9817-cd14d51ae2c4
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 30 Apr 2012 22:48:30 GMT

{"d":{"GetProtectionKeyId":"B2FE17BEF56FFCB9A3FC4267D0F2AFE25CD2DE22"}}

下列範例示範如何使用在前一步驟取得的 ProtectionKeyId,來擷取 X.509 憑證。

GET https://media.windows.net/API/GetProtectionKey?ProtectionKeyId='B2FE17BEF56FFCB9A3FC4267D0F2AFE25CD2DE22' HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1335935139&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=s2dI0Ulkutx%2b5pTL0QGRnPQEv1Ogwz%2ff2SHRWK8bmyw%3d
Host: media.windows.net

如果成功,會傳回以下回應:

HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 1061
Content-Type: application/json;odata=verbose;charset=utf-8
Server: Microsoft-IIS/7.5
x-ms-request-id: 1a84817d-9967-4adc-92d9-5980b2cd5d45
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 01 May 2012 19:05:44 GMT

{"d":{"GetProtectionKey":"MIIDAjCCAe6gAwIBAgIQVq/2JBMjhoNDGQ93Rh6lhDAJBgUrDgMCHQUAMBkxFzAVBgNVBAMTDm5pbWJ1c2RldmNlcnQxMB4XDTExMDUwNDE4NDczOVoXDTM5MTIzMTIzNTk1OVowGTEXMBUGA1UEAxMObmltYnVzZGV2Y2VydDEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCd/070wkNh/UuXZNVIkc8uflSMm+Qy6RDoAwdnl3fispkbe28YbB6AMuENKq9UrfUigGf51+MKnLaojxwwpwS+kdrRh+qQ7LBM0tjQ4bK1Iq80Q8dyQLpqqo6v16NzAFVeE4jW5205Z93h8m3EatQyyCGFN38BF9iIICeiPEjEEq4utDzeHgQT82enAdkqZ5mxRtOY3u3yT9O9HbS+Ghkobgg+kdbHpWlhSwSEKh94ASLeJvazL154OvIqfgZ7DaKQ11uAFqx237rNdX+w7JYHUQ4AZK2ed5xXTcXMcerUtjJZ4jiky83WaP6wCMcaA4R+76x3q8B91Rs3LS9yyqmRAgMBAAGjTjBMMEoGA1UdAQRDMEGAEIZT7vc/79JcQWslkhGbOCahGzAZMRcwFQYDVQQDEw5uaW1idXNkZXZjZXJ0MYIQVq/2JBMjhoNDGQ93Rh6lhDAJBgUrDgMCHQUAA4IBAQAcMOz4ScCP8F0VRkPjWPWDrLwD1rj5lwOTXvEL8tR23nrifkWgFQgONzMndp+FIgtoMLfb+6Cs0ZkslL/8cJ3zYWx+e1pSZydV3Ke9oSOVLWbWBtQgniBdb/b+/ur53NEkNxWzkTcM9UCg/pcLs9sKja2Kz8R12FUaf+2fOUBf2m0oRM9cyvoeBiI2AHX6Uo2WXpJixa8ofydB94oAbt/04lDMAHryrD1BAJR76z3gB6PLb4L12LDqeXjAIc6hgtrNsYBJMQAv4KDHcmHW1601QGuQsy+V4I35Y7bOQUNyTZRlUpLu0E/RRVKjyyMBDTE0xXABt4w23nNyczpH/4U3"}}
note附註
訊息本文中的憑證是 base64 編碼,但必須先解碼才能使用。

擷取 X.509 憑證並使用其公開金鑰將內容金鑰加密之後、建立 ContentKey 實體,然後據以設定其屬性值。

下列範例示範如何建立 ContentKey,將 ContentKeyType 設定為儲存體加密 (「1」) 及 ProtectionKeyType 設定為「0」,以指示保護金鑰識別碼是 X.509 憑證指紋。您還必須定義 ContentKey 實體的識別碼或金鑰識別碼。此值必須是 GUID 值,而且符合內容識別碼配置 nb:kid:UUID:GUID。如需內容識別碼配置的詳細資訊,請參閱Identify Azure Media Services Entities;如需 ContentKeys 的詳細資訊,則請參閱ContentKey

POST https://media.windows.net/API/ContentKeys HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336404839&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=JtpNaFsZWEq9WHl3zMcPbvxBg3HyfTRo%2fy7WEqNDFpw%3d
Host: media.windows.net
Content-Length: 223
Expect: 100-continue

{"Id" : "nb:kid:UUID:C02BB13C-94C3-426B-9DE3-1E331584EF7A", "ContentKeyType" : 1, "EncryptedContentKey" : "encrypted key value",  "ProtectionKeyId" : "B2FE17BEF56FFCB9A3FC4267D0F2AFE25CD2DE22", "ProtectionKeyType" : 0, "Checksum" : "checksum value"}

如果成功,會傳回以下回應:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 614
Content-Type: application/json;odata=verbose;charset=utf-8
Location: https://media.windows.net/api/ContentKeys('nb%3Akid%3AUUID%3Ac02bb13c-94c3-426b-9de3-1e331584ef7a')
Server: Microsoft-IIS/7.5
x-ms-request-id: 1d990cfc-acf1-4838-9f6e-c9308e51279e
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 07 May 2012 05:34:01 GMT

{"d":{"__metadata":{"id":"https://media.windows.net/api/ContentKeys('nb%3Akid%3AUUID%3Ac02bb13c-94c3-426b-9de3-1e331584ef7a')","uri":"https://media.windows.net/api/ContentKeys('nb%3Akid%3AUUID%3Ac02bb13c-94c3-426b-9de3-1e331584ef7a')","type":"Microsoft.Cloud.Media.Vod.Rest.Data.Models.ContentKey"},"Id":"nb:kid:UUID:c02bb13c-94c3-426b-9de3-1e331584ef7a","Created":"\/Date(1336368841597)\/","LastModified":"\/Date(1336368841597)\/","ContentKeyType":1,"EncryptedContentKey":"encrypted key value","Name":null,"ProtectionKeyId":"B2FE17BEF56FFCB9A3FC4267D0F2AFE25CD2DE22","ProtectionKeyType":0,"Checksum":"checksum value"}}

建立了 ContentKey 之後,使用 $links 作業將它與您的 Asset 產生關聯,如下列範例所示:

POST https://media.windows.net/API/Assets('nb:cid:UUID:2973c0de-404e-4f21-83a3-efd6910a532b')/$links/ContentKeys HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fmediaservices.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336404839&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=JtpNaFsZWEq9WHl3zMcPbvxBg3HyfTRo%2fy7WEqNDFpw%3d
Host: media.windows.net
Content-Length: 120

{"uri":"https://media.windows.net/api/ContentKeys('nb%3Akid%3AUUID%3Ac02bb13c-94c3-426b-9de3-1e331584ef7a')" }

如果成功,會傳回 204 回應碼,且不含訊息本文。

將檔案上傳到 Blob 儲存體需要設定資產的適當寫入權限,擷取要上傳檔案的 URL,最後再使用 Azure Storage REST API 執行實際的上傳。

將任何檔案上傳到 Blob 儲存體之前,請設定寫入資產的存取原則權限。設定方式是將 HTTP 要求「張貼」到 AccessPolicies 實體集。在建立時定義 DurationInMinutes 值,否則會在回應中收到 500 內部伺服器錯誤訊息。如需 AccessPolicies 的詳細資訊,請參閱AccessPolicy

下列範例示範如何建立 AccessPolicy:

POST https://media.windows.net/API/AccessPolicies HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1335956356&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=1B1ysfYRcpI%2fQY9SSNIBBVBpgc67j4R2yXD7BCxs8D8%3d
Host: media.windows.net
Content-Length: 76
Expect: 100-continue

{"Name": "NewUploadPolicy", "DurationInMinutes" : "300", "Permissions" : 2 }

如果成功,會傳回以下回應:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 526
Content-Type: application/json;odata=verbose;charset=utf-8
Location: https://media.windows.net/api/AccessPolicies('nb%3Apid%3AUUID%3A94763883-537a-41c0-a097-4e3f755bbeab')
Server: Microsoft-IIS/7.5
x-ms-request-id: 0a262141-e539-4fa6-b5d6-80cdf26d3ff6
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 02 May 2012 00:59:30 GMT

{"d":{"__metadata":{"id":"https://media.windows.net/api/AccessPolicies('nb%3Apid%3AUUID%3A94763883-537a-41c0-a097-4e3f755bbeab')","uri":"https://media.windows.net/api/AccessPolicies('nb%3Apid%3AUUID%3A94763883-537a-41c0-a097-4e3f755bbeab')","type":"Microsoft.Cloud.Media.Vod.Rest.Data.Models.AccessPolicy"},"Id":"nb:pid:UUID:94763883-537a-41c0-a097-4e3f755bbeab","Created":"\/Date(1335920371136)\/","LastModified":"\/Date(1335920371136)\/","Name":"NewUploadPolicy","DurationInMinutes":300,"Permissions":2}}

建立 AccessPolicy 之後,將其連結到 Locator 實體,此實體會提供將您的檔案上傳到 Blob 儲存體的 URL 路徑。

若要接收實際的上傳 URL,請建立 Locator 實體。Locator 會為希望存取 Asset 中檔案的用戶端,定義連線端點的開始時間及類型。您可以為指定的 AccessPolicy 與 Asset 配對建立多個 Locator 實體,以處理不同的用戶端要求與需求。這些 Locator 都會使用 AccessPolicy 的 StartTime 值和 DurationInMinutes 值,從而決定 URL 可使用的時間長度。如需詳細資訊,請參閱Locator

note附註
資產同時最多只能有五個關聯的唯一定位器。如需詳細資訊,請參閱Locator

Tip提示
如果需要立即上傳您的檔案,應該將 StartTime 值設定為目前時間的五分鐘前。這是因為您的用戶端電腦與 媒體服務 之間可能有時間差。此外,您的 StartTime 值必須為以下 DateTime 格式:YYYY-MM-DDTHH:mm:ssZ (例如 "2014-05-23T17:53:50Z")。

note附註
從建立定位器到可以使用定位器,這中間可能會有 30 到 40 秒的延遲。SAS URL 與原始定位器都會發生這樣的延遲問題。

下列範例顯示如何建立 SAS URL 定位器,如要求本文的 Type 屬性所定義。傳回的 Path 屬性包含必須用來上傳您檔案的 URL。

POST https://media.windows.net/API/Locators HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1335956356&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=1B1ysfYRcpI%2fQY9SSNIBBVBpgc67j4R2yXD7BCxs8D8%3d
Host: media.windows.net
Content-Length: 183
Expect: 100-continue

{"AccessPolicyId": "nb:pid:UUID:94763883-537a-41c0-a097-4e3f755bbeab", "AssetId" : "nb:cid:UUID:cab358e0-deaa-4c4f-9a9f-35687b54b0aa", "StartTime" : "2014-05-17T16:45:53", "Type" : 1 }

如果成功,會傳回以下回應:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Length: 1148
Content-Type: application/json;odata=verbose;charset=utf-8
Location: https://media.windows.net/api/Locators('nb%3Alid%3AUUID%3A8002bf3c-a215-4602-b4a4-2aac367f709e')
Server: Microsoft-IIS/7.5
x-ms-request-id: 6937fd51-70ad-4d3d-8138-991863906b43
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 02 May 2012 00:59:30 GMT

{"d":{"__metadata":{"id":"https://media.windows.net/api/Locators('nb%3Alid%3AUUID%3A8002bf3c-a215-4602-b4a4-2aac367f709e')","uri":"https://media.windows.net/api/Locators('nb%3Alid%3AUUID%3A8002bf3c-a215-4602-b4a4-2aac367f709e')","type":"Microsoft.Cloud.Media.Vod.Rest.Data.Models.Locator"},"AccessPolicy":{"__deferred":{"uri":"https://media.windows.net/api/Locators('nb%3Alid%3AUUID%3A8002bf3c-a215-4602-b4a4-2aac367f709e')/AccessPolicy"}},"Asset":{"__deferred":{"uri":"https://media.windows.net/api/Locators('nb%3Alid%3AUUID%3A8002bf3c-a215-4602-b4a4-2aac367f709e')/Asset"}},"Id":"nb:lid:UUID:8002bf3c-a215-4602-b4a4-2aac367f709e","ExpirationDateTime":"\/Date(1335938672000)\/","Type":1,"Path":"https://yourstorageaccount.blob.core.windows.net/asset-0a5ed405-ac50-45c7-a3bf-04d20eca17ad?st=2012-05-02T01%3A04%3A32Z&se=2012-05-02T06%3A04%3A32Z&sr=c&si=8002bf3c-a215-4602-b4a4-2aac367f709e&sig=r9IVlPDi4TfaCnG8fqpZUwr%2F3pMPsdFyVVYkwe6GKg0%3D","AccessPolicyId":"nb:pid:UUID:94763883-537a-41c0-a097-4e3f755bbeab","AssetId":"nb:cid:UUID:cab358e0-deaa-4c4f-9a9f-35687b54b0aa","StartTime":"\/Date(1335920672000)\/"}}

設定 AccessPolicy 與 Locator 之後,使用 Azure Storage REST API 將實際檔案上傳到 Azure Blob 儲存體容器。您可以使用頁面或區塊 Blob 上傳。如需上傳 Blob 的詳細資訊,請參閱Azure 儲存服務 REST API 參考

下列範例顯示如何從 SDK 媒體範例上傳區塊 Blob 到 Asset 容器。

note附註
您必須將要上傳之檔案的檔案名稱,加入在前一節收到的 Locator Path 值。在此範例中,檔案名稱是 samplevid.wmv。

PUT https://yourstorageaccount.blob.core.windows.net/asset-9cd47271-9798-446f-b91d-22b0d228cc17/samplevid.wmv?st=2012-05-08T19%3A32%3A01Z&se=2012-05-09T00%3A32%3A01Z&sr=c&si=3e21040c-95d8-48b0-aee5-171d9621105d&sig=%2FSS6c%2FOELEtDfqi5TT7hFLYut38IKrV6iiQEhV2t52s%3D HTTP/1.1
Content-Type: application/octet-stream
x-ms-version: 2011-08-18
x-ms-date: 2011-01-17
x-ms-blob-type: BlockBlob
Host: yourstorageaccount.blob.core.windows.net
Content-Length: 4045744
Expect: 100-continue

wsh?1hfN??C?V??,?-?sd??:?j?dCfT?,?6????8?f?p??o??"?????6C??q?????KbP???w*????i
[Rest of binary data truncated for readability]

如果成功,會傳回以下回應:

HTTP/1.1 201 Created
Transfer-Encoding: chunked
Content-MD5: 2Lzhghji5MH0CZ+EUidXyA==
Last-Modified: Tue, 08 May 2012 19:37:16 GMT
ETag: "0x8CEFB691BBEDD64"
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 4902799b-568f-49a8-893c-77fbee74ce18
x-ms-version: 2011-08-18
Date: Tue, 08 May 2012 19:37:15 GMT

0

上傳檔案之後,應該「刪除」上傳定位器,以撤銷對您資產的 Blob 儲存體容器的寫入存取權限。

DELETE https://media.windows.net/api/Locators('nb%3Alid%3AUUID%3A81e5bd32-46ad-4d66-b7b8-50008ee4aec5') HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336547485&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=ISzXspEIbgWifYYXqiPK1vo3%2bDHnTsX85umNxRjD3kQ%3d
Host: media.windows.net
Content-Length: 0

如果成功,會傳回 204 回應碼,且不含訊息本文。

既然您已經上傳檔案,現在請為其產生 File 實體。此實體包含與您檔案相關的重要中繼資料,而且可藉由呼叫 CreateFileInfos 加以建立 (如下列範例所示)。

GET https://media.windows.net/api/CreateFileInfos?assetid='nb%3Acid%3AUUID%3Ac80d312d-7cb1-44aa-bb23-2c35d10c44bd' HTTP/1.1
Content-Type: application/json;odata=verbose
Accept: application/json;odata=verbose
DataServiceVersion: 3.0
MaxDataServiceVersion: 3.0
x-ms-version: 2.5
Authorization: Bearer http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=youraccountname&urn%3aSubscriptionId=2f84471d-b1ae-4e75-aa09-010f0fc0cf5b&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&Audience=urn%3aWindowsAzureMediaServices&ExpiresOn=1336547485&Issuer=https%3a%2f%2fwamsprodglobal001acs.accesscontrol.windows.net%2f&HMACSHA256=ISzXspEIbgWifYYXqiPK1vo3%2bDHnTsX85umNxRjD3kQ%3d
Host: media.windows.net
Content-Length: 0

如果成功,會傳回 204 回應碼,且不含訊息本文。

如果已將任何檔案加密,必須根據下表更新 File 實體的屬性。如需如何更新實體的範例,請參閱使用媒體服務 REST API 管理資產。如需 File 實體屬性的詳細資訊,請參閱AssetFile

 

屬性 加密類型

IsEncrypted

若是儲存體與一般加密,值必須設定為「true」。

儲存體、一般

EncryptionKeyId

加密 ContentKey 識別嗎。

儲存體

EncryptionScheme

對於儲存體加密,值必須設為「StorageEncryption」。對於一般加密,值必須設為「CommonEncryption」。

儲存體、一般

EncryptionVersion

值必須設為 "1.0"。

儲存體、一般

InitializationVector

先前定義的初始化向量值。

儲存體

如果成功,會傳回 204 回應碼,且不含訊息本文。

另請參閱

顯示:
© 2014 Microsoft