Asked by:
How to add Storage to my website?

Question
-
User-1322569703 posted
This is how I use Storage from azure to upload photos and retrieve images from.
How do I get on to the best of these things?
I do not think I can find anything about it so that I can move on to doing these things.
I have read hereFriday, June 30, 2017 4:42 PM
All replies
-
User1068175894 posted
Could you explain your question in more details?
Friday, June 30, 2017 7:20 PM -
User-1322569703 posted
That's the way I need to download some files and upload. How can you do that?
Friday, June 30, 2017 8:36 PM -
User-271186128 posted
Hi Jesper Petersen,
how I use Storage from azure to upload photos and retrieve images from.To the Photos files, I suggest you could use Blob Storage to store them.
More details about Azure Storage and choose between these features, see:
https://docs.microsoft.com/en-us/azure/storage/storage-introduction
https://docs.microsoft.com/en-us/azure/storage/storage-decide-blobs-files-disks
If you want to use Azure Blob storage, please refer to the following code:
private async Task<CloudBlockBlob> UploadAndSaveBlobAsync(HttpPostedFileBase imageFile) { string blobName = Guid.NewGuid().ToString() + Path.GetExtension(imageFile.FileName); CloudBlockBlob imageBlob = imagesBlobContainer.GetBlockBlobReference(blobName); using (var fileStream = imageFile.InputStream) { await imageBlob.UploadFromStreamAsync(fileStream); } return imageBlob; }
More details, see:
https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-dotnet-get-started
If you still want to use File Storage, please refer to the following code:
CloudStorageAccountstorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageAccountConnectionString"]); CloudFileClientfileClient = storageAccount.CreateCloudFileClient(); CloudFileSharefileShare = fileClient.GetShareReference("sharedfiles"); if (fileShare.Exists()) { string policyName = "DemoPolicy" + new Random().Next(50); FileSharePermissionsfileSharePermissions = fileShare.GetPermissions(); // define policy SharedAccessFilePolicysharedAccessFilePolicy = newSharedAccessFilePolicy() { SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1), Permissions = SharedAccessFilePermissions.Read //Permissions = SharedAccessFilePermissions.Write }; fileSharePermissions.SharedAccessPolicies.Add(policyName, sharedAccessFilePolicy); // set permissions of file share fileShare.SetPermissions(fileSharePermissions); // generate SAS token based on policy and use to create a new file CloudFileDirectoryrootDirectory = fileShare.GetRootDirectoryReference(); if (rootDirectory.Exists()) { CloudFileDirectorycustomDirectory = rootDirectory.GetDirectoryReference("Shared Content"); if (customDirectory.Exists()) { CloudFile file = customDirectory.GetFileReference("DemoFile.txt"); stringsasToken = file.GetSharedAccessSignature(null, policyName); //generate URL of file with SAS token UrifileSASUrl = newUri(file.StorageUri.PrimaryUri.ToString() + sasToken); CloudFilenewFile = newCloudFile(fileSASUrl); newFile.UploadText("Hello!"); } } } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } finally { Console.WriteLine("Enter to exit.."); Console.ReadLine(); }
and:
try { CloudStorageAccountstorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageAccountConnectionString"]); CloudFileClientfileClient = storageAccount.CreateCloudFileClient(); CloudFileSharefileShare = fileClient.GetShareReference("sharedfiles"); if (fileShare.Exists()) { CloudFileDirectoryrootDirectory = fileShare.GetRootDirectoryReference(); if (rootDirectory.Exists()) { CloudFileDirectorycustomDirectory = rootDirectory.GetDirectoryReference("Shared Content"); if (customDirectory.Exists()) { CloudFile file = customDirectory.GetFileReference("The Word.docx"); if (file.Exists()) { Console.WriteLine("Downloading file.."); DownloadFileFromShare(file, @ "D:\Downloaded_The_Word.docx"); } } } } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } finally { Console.WriteLine("Enter to exit.."); Console.ReadLine(); }
More details, see:
http://www.c-sharpcorner.com/article/guide-to-azure-file-storage/
Best regards,
DillionMonday, July 3, 2017 10:00 AM