Created
February 1, 2019 02:42
-
-
Save donma/14839957cd7cf52135ae9d55664f6663 to your computer and use it in GitHub Desktop.
Azure Blob Storage Get File URL and Permission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var connsctionString = "your_connection_string"; | |
var cloudStorage = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connsctionString); | |
var cloudBlobClient = cloudStorage.CreateCloudBlobClient(); | |
var cloudBlobContainer = cloudBlobClient.GetContainerReference("donmablogsample"); | |
var resultCreateContainer = cloudBlobContainer.CreateIfNotExistsAsync().Result; | |
Console.WriteLine("donmablogsample create already."); | |
// 設定可以開啟 60 秒,並且此簽章只能夠讀取 | |
var sharedPolicy = new Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPolicy() | |
{ | |
SharedAccessExpiryTime = DateTime.UtcNow.AddSeconds(60), | |
Permissions = Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Read, | |
}; | |
var sasContainerToken = cloudBlobContainer.GetSharedAccessSignature(sharedPolicy, null); | |
Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory = | |
cloudBlobContainer.GetDirectoryReference("TEST2/TEST21/"); | |
var uri = cloudBlobDirectory.GetBlockBlobReference("sampleText9.json").Uri; | |
Console.WriteLine("TEST2/TEST21/sampleText9.json Download Uri =>" + uri + sasContainerToken); | |
//這一行非必要 ,呼叫系統瀏覽器開始網址而已 | |
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("cmd", $"/c start " + uri + sasContainerToken.Replace("&", "^&")) { CreateNoWindow = true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment