Can I create a SAS URL to store Azure files (i.e. Not Blobs)

Using windows azure blob storage and providing access through a URL with a shared signature is all fine and healthy. Can I do the same using files stored in the new Azure file vault?

The Get Blob REST api says that you can use the shared signature , but Get documents API REST files . Therefore, I do not think so .

If this is not possible, then what proposed approach gives temporary access to someone? Create a copy as blob and use SAS for this or just don't use File Storage for this scenario?

+5
source share
3 answers

The latest version of WindowsAzure.Storage version 5.0.0 has an API for creating SAS for sharing Azure files.

Example (taken from the Tool or an example of use for generating and viewing SAS (shared signatures) of both Azure Block Blob and Azure File Share ):

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)) }); } 

Feel free to also check out this free tool: EverDir.com

+5
source

It is not possible to create a shared signature for the Azure File Service at this time.

If this is not possible, then what proposed approach gives temporary access to someone? Create a copy as blob and use SAS for this, or just don't use File Storage for this scenario?

I would say this is currently the best approach for this. Another option would be to proxy your file services repository with your application.

+3
source

I think my answer is too late, but maybe someone is looking for the same topic. I had the same problem and found information only about blobs, but after a little research, I was able to create this method in C #, which returns the SAS URL

First install the AzureStorage library in your project using the NuGet management tool

 using Microsoft.Azure; using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.File; 

And here you have the code

 public string GetFromUrl(string folder, string fileName) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=yourStorageAcountName;AccountKey=yourKey"); CloudFileClient fileClient = storageAccount.CreateCloudFileClient(); Uri myUri = new Uri("https://yourAcount.file.core.windows.net/yourDirectory/"+ folder); CloudFileDirectory directory = new CloudFileDirectory(myUri, storageAccount.Credentials); var result = GetFileSasUri(directory, fileName); return result; } static string GetFileSasUri(CloudFileDirectory container, string fileName) { CloudFile file = container.GetFileReference(fileName); SharedAccessFilePolicy sasConstraints = new SharedAccessFilePolicy(); sasConstraints.SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5); sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24); sasConstraints.Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.Write; string sasBlobToken = file.GetSharedAccessSignature(sasConstraints); SharedAccessFilePolicy sharedPolicy = new SharedAccessFilePolicy() { SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24), Permissions = SharedAccessFilePermissions.Write | SharedAccessFilePermissions.List | SharedAccessFilePermissions.Read }; return file.Uri + sasBlobToken; } 

In this example, the Folder option may be empty or must end with "/". The file name must have an extension (for example, audio.mp3) Note that the link has an expiration date, but you can add hours, days, and even years for this;)

Hope this helps you.

+2
source

Source: https://habr.com/ru/post/1208047/


All Articles