user2510304
user2510304

Reputation: 45

How do I obtain a SAS (shared Access signature) from a locator in Azure?

I'm using Azure media services. I tried to obtain a SAS by creating a locator, and then getting the baseURI property of it. The SAS I got by doing that is:

https://rfsstorage.blob.core.windows.net/asset-02b45419-74fd-48cc-bdb8-dd66e0d88055

But is that really a SAS? Or is it something else? It certainly doesn't work with other code that I borrowed from the internet that expects a SAS. Here is the few lines of code I used to obtain the SAS:

Public Sub OtainSAS(ByVal Filename As String)
        Dim mediaServicesAccountName As String = ConfigurationManager.AppSettings("accountname")
        Dim mediaServicesAccountKey As String = ConfigurationManager.AppSettings("accountkey")
        Dim mediaCloud As New CloudMediaContext(mediaServicesAccountName, mediaServicesAccountKey)
        Dim assetOptions As New AssetCreationOptions()
        Dim asset = mediaCloud.Assets.Create(Filename, assetOptions)

        Dim assetFile = asset.AssetFiles.Create(Filename)

        Dim accessPolicy = mediaCloud.AccessPolicies.Create(Filename, TimeSpan.FromDays(3), AccessPermissions.Write Or AccessPermissions.List)

        Dim locator As ILocator
        locator = mediaCloud.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy)

        gSasURL = locator.BaseUri

        locator.Delete()
        accessPolicy.Delete()
    End Sub

Thanks.

Upvotes: 0

Views: 368

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136306

The link above is certainly not SAS. If you read the documentation for Locator here: http://msdn.microsoft.com/en-us/library/windowsazure/hh974308.aspx#create_a_locator, you will notice that BaseUri is defined as

Part of the locator that provides the store/service/container information about the asset. (for example, Dns Host name http://someservice.cloudapp.net)

There's another property called ContentAccessComponent which gets returned as a part of locator and that contains the SAS. So in your code this is what you would do:

uploadSasUrl = locator.BaseUri & 'File Name' & locator.ContentAccessComponent

Basically you will concatenate BaseUri, file which is being uploaded and ContentAccessComponent. Do give it a try.

Also I noticed that you're deleting the access policy once you get the locator. I think you would need to keep the access policy in place till the time blob is uploaded.

Upvotes: 1

Related Questions