在Windows Azure媒体服务中签名URL

时间:2013-04-19 16:23:37

标签: azure cdn akamai azure-media-services

我正在尝试在Windows Azure Media Services中找到与以下S3功能相同的功能:http://www.bucketexplorer.com/documentation/amazon-s3--how-to-generate-url-for-amazon-s3-file.html#signedurl

我听说过这样的签名网址可以通过S3以及CDN(如Akamai)来实现。

2个问题。

1)是否有人建议如何在WAMS中实施签名URL?

2)有人知道Azure将与Akamai等其他CDN挂钩吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

Windows Azure中此功能的等效项称为Shared Access Signature。媒体服务确实支持创建SAS Origin Locators

您可以阅读how to create SAS Locator with .NET SDK上的官方文档。

或者您可以查看my project on GitHubLocators implementation in particular

用于为特定资产生成SAS定位器的代码示例如下:

public string GetSasLocator(IAsset asset)
{
    // Create an 1-day readonly access policy. 
    IAccessPolicy streamingPolicy = this.MediaService.MediaContext.AccessPolicies.Create("Full Access Policy",
        TimeSpan.FromMinutes(20),
        AccessPermissions.List | AccessPermissions.Read | AccessPermissions.Read);

    // Create the origin locator. Set the start time as 5 minutes 
    // before the present so that the locator can be accessed immediately 
    // if there is clock skew between the client and server.
    ILocator sasLocator =
        (from l in this.MediaService.MediaContext.Locators
         where l.Type == LocatorType.Sas && l.AssetId.Equals(asset.Id)
         select l).FirstOrDefault();

    if (sasLocator != null && sasLocator.ExpirationDateTime < DateTime.UtcNow)
    {
        sasLocator.Delete();
        sasLocator = null;
    }

    if (sasLocator == null)
    {
        sasLocator = this.MediaService.MediaContext
            .Locators.CreateSasLocator(asset,
         streamingPolicy,
         DateTime.UtcNow.AddMinutes(-5));
    }
    // Create a full URL to the manifest file. Use this for playback
    // in streaming media clients. 
    string sasUrl = sasLocator.Path;

    // Display the full URL to the streaming manifest file.
    Console.WriteLine("URL to for blob upload: ");
    Console.WriteLine(sasUrl);

    return sasUrl;
}