导出 (0) 打印
全部展开

使用 Media Services REST API 引入资产

更新时间: 2014年2月

注:本页面内容可能不完全适用中国大陆地区运营的 Windows Azure服务。如要了解不同地区 Windows Azure 服务的差异, 请参考本网站.

使用 REST API 将资产引入 Microsoft Azure Media Services包括多个步骤。对于某些操作(如加密资产),这要求你在与媒体服务交互之前执行多个步骤。但是,大多数操作(如创建资产本身)都非常直接,只要求你了解 REST 原理、OData v3 和 JSON(对于代码示例)的基本知识。

引入资产的基本工作流分为以下部分:

有关批量引入资产的信息,请参阅使用 REST API 批量引入资产

note注意
构建流内容的 URL 时,Media Services 会使用 IAssetFile.Name 属性的值(如 http://{WAMSAccount}.origin.mediaservices.windows.net/{GUID}/{IAssetFile.Name}/streamingParameters)。出于这个原因,不允许使用百分号编码。Name 属性的值不能含有任何以下保留的百分号编码字符:!*'();:@&=+$,/?%#[]"。此外,文件扩展名中只能含有一个“.”。

Important重要提示
使用 Media Services 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 证书,并且需要在资产、ContentKey 和文件实体上设置对应的属性。内容密钥长度因内容密钥类型而异。存储和配置加密需要 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 证书的公钥加密你的内容密钥。此外,请基于加密的内容密钥创建一个 MD5 校验和值。

  6. 创建一个 ContentKey 实体并使用你在上一步收到的值设置 EncryptedContentKey(已转换为 base64 编码的字符串)、ProtectionKeyId、ProtectionKeyType、ContentKeyType 和 Checksum 属性。

  7. 通过 $links 操作将该 ContentKey 实体与你的资产实体关联。

  8. 上载文件(将在下一部分介绍)后,调用 CreateFileInfos 并使用你在前面的步骤中创建的值更新文件实体上的加密属性。

Important重要提示
本主题省略了定义加密密钥的示例,仅提供了说明如何与媒体服务交互的示例。

检索 ProtectionKeyId

以下示例说明了如何检索你在加密内容密钥时必须使用的证书的 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"}}

检索 ProtectionKey

以下示例说明了如何使用你在上一步收到的 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 编码,在使用之前必须解码。

创建 ContentKey

检索到 X.509 证书并使用其公钥加密你的内容密钥后,请创建一个 ContentKey 实体并相应地设置其属性值。

以下示例说明了如何创建 ContentKey,其中的 ContentKeyType 设置为“1”,表示将进行存储加密,而 ProtectionKeyType 则设置为“0”,表示保护密钥 ID 为 X.509 证书指纹。此外,还必须定义 ContentKey 实体的 ID 或密钥 ID。此值必须为 GUID 值并遵循内容标识符方案 nb:kid:UUID:GUID。有关内容标识符方案的详细信息,请参阅标识 Windows Azure Media Services 实体;有关 ContentKey 的详细信息,请参阅 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 操作将其与你的资产关联,如以下示例所示:

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 存储

将文件上载到 BLOB 存储要求你在资产上设置相应的写入权限,检索要将文件上载到的 URL,最后使用 Azure 存储 REST API 执行具体的上载操作。

设置 AccessPolicy

将任何文件上载到 BLOB 存储之前,请设置用于对资产执行写入操作的访问策略权限。为此,请向 AccessPolicy 实体集发送一个 HTTP POST 请求。请在执行创建操作时定义 DurationInMinutes 值,否则会在响应中收到 500 内部服务器错误消息。有关 AccessPolicy 的详细信息,请参阅 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 后,请将其链接到某个定位符实体,该实体将为你提供用于将文件上载到 BLOB 存储的 URL 路径。

获取上载 URL

若要检索具体的上载 URL,请创建一个定位符实体。定位符为希望访问资产中文件的客户端定义连接终结点的开始时间和类型。可以为给定 AccessPolicy 和资产对创建多个定位符实体,以处理不同的客户端请求和需求。这其中的任一定位符都可使用 AccessPolicy 的 StartTime 值和 DurationInMinutes 值来确定可以使用某 URL 的时间长度。有关详细信息,请参阅定位符

note注意
一项给定的资产一次最多只能与五个唯一的定位符相关联。有关详细信息,请参阅定位符

Tip提示
如果需要立即上载文件,应将 StartTime 值设置为当前时间前五分钟。这是因为你的客户端计算机与媒体服务之间可能存在时钟偏差。此外,StartTime 值必须采用以下 DateTime 格式:YYYY-MM-DDTHH:mm:ssZ(例如,“2014-05-23T17:53:50Z”)。

note注意
定位符从创建到可用可能会有 30-40 秒的延迟。SAS URL 和源定位符都会出现这个问题。

以下示例说明了如何创建 SAS URL 定位符(由请求正文中的类型属性定义)。返回的路径属性包含你必须用于上载文件的 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 和定位符后,即可使用 Azure 存储 REST API 将具体的文件上载到 Azure BLOB 存储容器。也可以按页或块 BLOB 来上载。有关上载 BLOB 的详细信息,请参阅 Azure Storage Services REST API Reference(Azure 存储服务 REST API 参考)。

以下示例说明了如何将 SDK 媒体示例中的块 BLOB 上载到资产容器中。

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

撤销上载 URL(可选)

上载文件后,你应删除上载定位符,以撤销对你资产的 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 响应代码。

生成文件元数据

上载文件后,请为其生成文件实体。此实体包含有关你的文件的重要元数据,并且可以通过调用 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 响应代码。

如果你加密了任何文件,则需要根据下表更新文件实体上的属性。有关如何更新实体的示例,请参阅使用 Media Services REST API 管理资产。有关文件实体属性的详细信息,请参阅AssetFile

 

属性 加密类型

IsEncrypted

对于存储和常用加密,必须将此值设置为“true”。

存储、常用

EncryptedKeyId

已加密的 ContentKey ID。

存储

EncryptionScheme

对于存储加密,该值必须设置为“StorageEncryption”。对于常用加密,该值必须设置为“CommonEncryption”。

存储、常用

EncryptionVersion

该值必须设置为“1.0”。

存储、常用

InitializationVector

前面定义的初始化向量值。

存储

如果成功,将返回不带消息正文的 204 响应代码。

另请参见


构建日期:

2014-06-20

社区附加资源

添加
Microsoft 正在进行一项网上调查,以了解您对 MSDN 网站的意见。 如果您选择参加,我们将会在您离开 MSDN 网站时向您显示该网上调查。

是否要参加?
显示:
© 2014 Microsoft