How To Upload File In Azure Storage From Mvc
This is an amazing feel for me to piece of work with Azure Blob Storage in ASP.NET MVC awarding. I am going to share some avant-garde part which I have learned.
Equally we all know Azure Blob Storage is used to store the Binary Big Objects [Blobs]. Here nosotros can store and retrieve different kinds of data similar images, documents, media files, etc.
Agenda of this Article
What is Blob Storage
Windows Azure Blob Storage can store the hundreds of terabytes data in ane account. Every bit y'all know you can create multiple blob storage account, so definitely yous can store multiple hundreds of terabytes data with Windows Azure Hulk Storage.
We don't crave taking tension about the backup of the data which is stored on blob storage. It is because it automatically takes the backed upwardly data. You can increment your storage every bit per requirement and you need to pay only which you lot accept used and what you lot have used.
One more than thing, I want to consider here that you don't need to take headache almost how to manage your data, your VM or any other things; actually Windows Azure manages everything automatically.
You can utilise Blob Storage as Remainder API and tin employ with any language like Java, .Internet, etc. Actually engineering science doesn't affair with blob storage. It ways all kinds of client can exist accessible to this storage.
Y'all tin can as well visit this article for brief about Windows Azure Storage.
Why Hulk Storage
Persistency is the chief advantage because nosotros use Blob Storage. Actually there are many ways to share your static content or files to someone. You tin can store information technology on Hard Bulldoze simply these instances are not persistent. If y'all are going to apply VMs then it is managed automatically by Windows Azure and you don't need to worry almost this.
So, basically you are going to put your information in persistent store for long term uses and then y'all need to go with Blob Storage.
Create Blob Storage Account
In that location are different kinds of storage with Windows Azure like Tables Storage, Queue Storage besides as Hulk Storage. Today we are going to piece of work with Hulk Storage.
To starting time with Blob Storage, first yous should accept a Azure Account also as Blob Storage business relationship. If you don't have the Windows Azure Account, yous can try with Free Trial.
If you accept MSDN subscription and then you can take benefits to your credit limits.
To login with Windows Azure Portal, you just need to become with Azure portal. Provide your credentials to login and enter the Portal.
When yous complete yous successful login with Azure Portal so you lot will become to the post-obit page [Come across the following image].
To create a Blob Storage account, click to New option which is resided in the following,
When you click to NEW and so choose Data Service option then choose Storage, then Quick Create.
It volition give yous the window where you can enter your blob storage URL and location [which region you want to create your blob storage]. So, here yous need to provide the storage proper name in URL textbox. One matter y'all need to consider hither that name is globally unique. When you are going to choose your blob storage location, please note that it will exist your chief location where your hulk storage information center will exist resided.
Below y'all volition find 1 more option "Geo Replication". If you select this pick, the replica of your information will be stored on different location in aforementioned region. Now it is time to create your Hulk Storage. And so, click on CREATE STORAGE ACCOUNT.
Information technology will take few minutes to create and configure your storage account. Really information technology create all types of setting for your storage account.
Later on few minutes, you will find that your storage account has created successfully. You volition become a successfully created message in condition bar.
From the below condition bar carte, y'all can discover ane more than choice there and it is "MANAGE Access KEYS". Actually we demand admission cardinal to work with storage account.
And then, click on the MANAGE Admission KEYS which is resided at bottom of the screen.
Here yous will run into 2 types of the access key, one is main and other one is secondary corresponding to your storage business relationship. You can copy your storage account access key to click on Re-create icon at the right side. If you think that someone knows the storage access key then you can regenerate the admission key using the "regenerate" option.
So, finally we have successfully created the storage account on Windows Azure. At present it is time to access the account. At that place are different types of mode to access your hulk storage.
Install and Utilize Azure Explorer
If you are working with Windows Azure Blob Storage and storing some files and then you lot need to view, rename, and delete the files. And so, y'all can utilise the Azure Explorer to access your blob storage.
Y'all take to install Azure Explorer to your system to straight admission to your blob storage. And so, you can utilize link to download your azure explorer.
Click on Download, within few seconds, you will become the setup file for Azure Explorer. Click on the setup file to run the setup and it volition be going to install the Azure Explorer for you lot.
When it will be installed successfully, an application icon volition be set within the program card. Go to starting time and observe Azure Explorer and click on information technology.
Information technology will ask for license terms and weather. Y'all need to check on checkbox and click on I Accept.
So, you take installed Azure Explorer successfully. It volition open the azure explorer for you as in the following. Here you will find the Azure Storage Account option where you will be finding the entire containers which contain the blob for y'all.
To add your account with Azure Explorer, Right click on Azure Storage Account and choose Add Connection to Azure Storage.
It will provide you different way to connect with storage business relationship. You demand to choose "Connect to Azure with an Storage Account Name and an Access Central". Every bit we know that we accept got access key earlier and click to Next.
In the next "Add together Windows Azure Storage Business relationship", provides you storage business relationship name and storage access key.
If you lot want to test your connection, you lot can utilise "Exam Connection" push.
And then, finally we accept added our account with Azure Explorer. You tin meet my storage account "mukeshdemostorage" added successfully.
As we all know that at that place should be a container to store the blob inside storage business relationship. And then, for creating the new container for blob, Correct click on your storage account "mukeshdemostorage" and choose New Blob Container.
It will open a dialog window where you can specify the name of the Hulk Container and Access Level. I am going to provide the name as "sampleimage" [Name ever should be in small letters] and there admission level as Private.
So, it will create a blob container "sampleimage" for me. As it is an azure explorer. Yous can directly paste the documents or files within information technology. I am going to paste [Upload] one of my images directly inside the "sampleimage" blob container.
Then, you tin can see that ane image is bachelor with name "Mukesh Kumar". Right click on the image and click on Copy Path. It volition directly copy the path of epitome which is resided on the server.
Going to access the paradigm, you can paste the URL inside the browser and press enter. You will come across the following error which says that you lot can't access this file because the access level of this file is Private and you can't access information technology from outside as publicly.
So, you need to change the admission level of your hulk container.
When you over again effort to access the same URL inside the browser, you will find the paradigm is uploaded through the Azure Explorer.
Create ASP.NET MVC Application
We accept successfully uploaded and access the same image from Azure Explorer. It is very easy. Only how it is possible through an application, then, complete this task I am going to create an MVC application from where I volition try to upload an image within the blob storage and admission it.
Then, create an MVC application "BlobStorageDemo" with No Authentication.
Equally I am going to upload an image, so create a controller "ImageController" from where nosotros volition perform all the activity of the image. Right Click on the Controllers, Add, and then Controller.
Provide the name of the Controller as "ImageController" and click to Add.
Install Storage Client Library and Configuration through NuGet
Generally when we create a uncomplicated awarding there is no reference of the Storage Client Library. And so to add this I am going to use NuGet Package Manager.
Right Click on the project and choose Manage NuGet Packages.
Information technology will open NuGet Package Manager for you lot. Type the azure storage inside the search and it will requite you the following package which can be installed. You lot demand to choose WindowsAzureStorage and click to Install.
It will give y'all some preview what it is going to install packages.
Information technology will have few minutes to install. When it will install successfully, you volition exist finding lots of extra references inside the Reference section forth with WindowsAzure.Storage.
You can also install Azure Configuration to access the configuration setting in awarding.
Upload Epitome through ASP.Internet MVC Application
So, going to access the blob storage through your services or controller, y'all need to use blob storage access fundamental. So, for the security purpose you can shop it inside the configuration files. Later nosotros tin can access information technology anytime from anywhere.
I am going to create a class "ConnectionString.cs" from where I will access the storage account proper name and storage access fundamental and create the connection string for blob storage. Please make certain you need to use two namespaces.
To accessing the Storage Business relationship, You can access it through the CloudStorageAccount class which can be accessed past account name and access central. Using the case of the CloudStorageAccount, y'all can access and create the case of the CloudBlobClient. Simply without accessing the blob container you can't admission the resource which is resided in container. And so, in this case, we need to use the CloudBlobContainer.
To access these Storage classes, you lot make sure you are calculation the post-obit namespace.
Equally we are going to upload and bear witness the latest uploaded image on the view, we need to make changes in the controller as in the following. I am going to upload image through the "Upload" Activeness and showing the latest image through the action "LatestImage",
To upload and testify the latest image, I have created ii different views. For uploading you can useupload.cshtml and for showing the latest epitome use LatestImage.cshtml.
It is fourth dimension to run the projection. And then, runt the project to printing F5 and get to the post-obit page to upload the paradigm, hither you can choose a prototype which is going to upload and click to submit.
When you click submit, it will upload your image inside the sampleimage blob storage container. And redirect to latest image folio with latest uploaded image.
You can check your uploaded image to refresh the Azure Explorer.
Decision
Then, today we accept learned what hulk storage is and why we need to use information technology. We have used blob storage to create an account with ASP.NET MVC application.
Suggest, what do you call up?
Thanks for reading this article, hope yous have enjoyed it. Please share your valuable feedback and suggestion through comments.
Source: https://www.c-sharpcorner.com/UploadFile/8a67c0/upload-image-in-azure-blob-storage-with-Asp-Net-mvc/
Posted by: cruzconarthery.blogspot.com
0 Response to "How To Upload File In Azure Storage From Mvc"
Post a Comment