Azure Storage in ASP.NET Core
As days are passing by, more and more projects are making their files properly saved and secured under the cloud storage service. The options are different and according to the preference of the individuals they change. For some GCloud is the best option and for some AWS S3 happens to be the option looked for. Then there is the Azure storage that is used by a great many individuals as well.
The Details that You would Require:
The Azure account set up is something that you will need to have before starting the process. You can get the first year free for their storage services, so definitely this is good news. As it does not have a free tier, the blob storage of Azure should not have had any cost, but actually the reality is different. Whether you are paying for it or not, cents are surely getting spent for the same. At the time your account setup process is done, you will have to visit to the Azure Portal and there you will be getting a complete list of instructions for setting up the storage account. Once that is done, then you will be able to have the proper key and detail for the same which you will be saving.
Setting Up the Nuget:
When you will be starting your project then there are some trial and error methods that you will have to follow. The Nuget Package Manager will be making things easier for your in this matter. Also, you should know that the code Install+Package Windows Azure.Storage is all that you will be needing for the same. For a full framework this same package you can use now.
Making the Container:
Making a container is important as it serves the purpose of storing the files there. The usage is here is as same as it is in Amazon buckets. It is true that the portal containers may be safer. But then, you will not get the full control over the same. Therefore it is better to make your own container.
After making the container, You are all set to upload the files. For that you will have to create one reference to the blob that you have. The code would be:
var newBlob = container.GetBlockBlobReference(“myfile”);
await newBlob.UploadFromFileAsync(@”path\myfile.png”);
The same way, you will also be able to download the blobs and for that the code is:
var newBlob = container.GetBlockBlobReference(“myfile”);
await newBlob.DownloadToFileAsync(“path/myfile.png”, FileMode.Create);
Apart from all these you can also lease files. All these process have become much easier now with the Azure ASP.NET system for you.
No comments:
Post a Comment