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.
source share