Step By Step Process To Upload Document In Azure Blob Storage Using .NET
Hi friend's, today we are going to understand how to upload document in azure blob storage. i read many blogs and articals about this but i couldn't find any useful blog for this or provided proper information about blob. i collect many information about azure blob and want to share with you. i hope it is useful for you.
Now first try to understand about azure blob.
- What is a blob Storage?
- Blob Service Concepts
- Create an Azure Storage Account
- Create a project in visual studio
- Install client library & Azure Configuration manager using nuget packages
- Code Upload a Image into a container
1. What Is a Blob Storage?
Azure blob Storage is a provide service, large amount of unstructured data in binary or text format.That can accessed from any where using HTTP or HTTPS.
Common use of blob storage:
- Using blob, image or documents upload directly to browser
- Using blob, Uploading video or audio
- Storing data for backup and restore
- Storing data for analysis by an on-premises or Azure-hosted service
2. Blob Service Concepts
- Storage Account: Storage Account is done through azure access storage account. General-purpose storage account or a Blob storage account which is specialised for storing objects/blobs. please check for more information About Azure Storage Account.
- Container: Container provider grouping of a set of blobs. an account can contains number of containers.NOTE: The container name must be an small lovercase.
- Blob: Hear Microsoft describe different type of blob mention below.
- Block Blobs: Are Storing text or binary file, such as media files.
- Page Blobs: can more efficient to read/write orations.Azure Virtual Machines use page blobs as OS and data disks.
- Append Blobs: Are similar to block blob type
3. Create an Azure Storage Account
- First Create an Azure portal account.
- To learn more, see Create a storage account.
- Then Create Azure Storage Account by using Storage Resource Provider Client Library for .NET
4. Create Project in Visual Studio
In Visual Studio, Create an Console application or project first.hear i create console application.
- Select File > New > Project
- Select Installed > Templates > Visual C# > Windows Classic Desktop
- Select Console App (.NET Framework)
- Enter a name for your application in the Name: field
- Select OK
5. Install client library & Azure Configuration manager using nuget packages
Hear two main package need to reference in your project.
- Microsoft Storage Client Library for .Net:
- In Visual Studio, Tool > NuGetPackage Manager > Package manager then use this command in command manager.
- PM> Install-Package WindowsAzure.Storage -Version 8.4.0
- Microsoft Azure Configuration Manager
- In Visual Studio, Tool > NuGetPackage Manager > Package manager then use this command in command manager.
- PM>Install-Package Microsoft.WindowsAzure.ConfigurationManager -Version 3.2.3
6. Code Upload a Image into a container
static void Main(string[] args)
{
UploadImageInToBlobStorage();
}
//Class file method
- Create one class file in created project like xxx.cs file.
- Created this class file Create Static method.
Below mention .net c# code for upload image using block blob type blob storage
static void Main(string[] args)
{
UploadImageInToBlobStorage();
}
//Class file method
public static void UploadImageInToBlobStorage()
{
// Block blob basics example
StartBlockBlobOperationsAsync().Wait();
}
private static async Task StartBlockBlobOperationsAsync()
{
{
// Block blob basics example
StartBlockBlobOperationsAsync().Wait();
}
private static async Task StartBlockBlobOperationsAsync()
{
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("adftechnobrainsblob");
if (await cloudBlobContainer.CreateIfNotExistsAsync())
{
await cloudBlobContainer.SetPermissionsAsync(
new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
}
);
}
CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference("Image Name Hear");
cloudBlockBlob.Properties.ContentType = filetype;
//HttpPostedFileBase file object property use InputStream
await cloudBlockBlob.UploadFromStreamAsync(Image Stream hear);
}
Nice blog
ReplyDelete