Tool or usage example to generate and view SAS (Shared Access Signatures) of both Azure Block Blob and Azure File Share
Asked Answered
J

1

2

I am looking for a tool or usage example to generate and view SAS (Shared Access Signatures) of both Azure Block Blob and Azure File Share. There are lots of examples for Block Blob and Containers but what about Azure File Share SAS examples or tools.

Jaundiced answered 17/8, 2015 at 5:46 Comment(1)
It took me a while, but I finally found a tool that generates SAS for Azure File Share and it also lets you view the content. EverDir.comJaundiced
F
5

Ability to create Shared Access Signature on a File Service Share is announced in the latest version of REST API. You must use Storage Client Library 5.0.0 for that purpose.

First, install this library from Nuget:

Install-Package WindowsAzure.Storage -Version 5.0.0

Then the process of creating a SAS on a File Service Share is very much similar to creating a SAS on a blob container. Please see sample code below:

    static void FileShareSas()
    {
        var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
        var fileClient = account.CreateCloudFileClient();
        var share = fileClient.GetShareReference("share");
        var sasToken = share.GetSharedAccessSignature(new Microsoft.WindowsAzure.Storage.File.SharedAccessFilePolicy()
            {
                Permissions = Microsoft.WindowsAzure.Storage.File.SharedAccessFilePermissions.List,
                SharedAccessExpiryTime = new DateTimeOffset(DateTime.UtcNow.AddDays(1))
            });
    }

In the above code, we're creating a SAS with List permission that will expire one day from current date/time (in UTC).

Also if you're looking for a tool to do so, may I suggest you take a look at Cloud Portam (Disclosure: I am building this tool). Recently we released the functionality to manage SAS on a Share.

Ferro answered 17/8, 2015 at 6:10 Comment(1)
Thanks! EverDir.com was also very helpful and the code you just posted works!Jaundiced

© 2022 - 2024 — McMap. All rights reserved.