Introduction

Last time, I published an article with the title “Upload Image to blob storage using Xamarin.Android”. In this article, you will learn how you can upload Images to blob storage through Xamarin.forms. I hope you will learn something amazing in xamarin.

Blob Storage

So, the first question that comes to mind is: what is blob storage?

Blob stands for Binary Large Object. Azure Blob Storage is a service for storing large amounts of unstructured object data, such as text or binary data. You can use Blob Storage to expose data publicly to the world, or to store application data privately. Related uses of Blob Storage include,

Serving images or documents directly to a browser

Storing files for distributed access

Streaming video and audio

Storing data for backup and restore, disaster recovery, and archiving

Storing data for analysis by an on-premises or Azure-hosted service

Create a storage account

Prerequisites

If you don't have an Azure subscription, create a free account before you begin.

Create a storage account

Now you are ready to create your storage account. Every storage account must belong to an Azure resource group. A resource group is a logical container for grouping your Azure services. When you create a storage account, you have the option to either create a new resource group, or use an existing resource group.

To create a general-purpose v2 storage account in the Azure portal, follow these steps:

In the Azure portal, select all services. In the list of resources, type Storage Accounts. As you begin typing, the list filters based on your input. Select Storage Accounts.

On the Storage Accounts window that appears, choose Add.

Select the subscription in which to create the storage account.

Under the Resource group field, select Create new. Enter a name for your new resource group, as shown in the following image.

Next, enter a name for your storage account. The name you choose must be unique across Azure. The name also must be between 3 and 24 characters in length, and can include numbers and lowercase letters only.

Select a location for your storage account, or use the default location.

Create a container

In the left menu for the storage account, scroll to the Blob service section, then select Blobs.

Select the + Container button.

Type a name for your new container. The container name must be lowercase, must start with a letter or number, and can include only letters, numbers, and the dash (-) character. For more information about container and blob names, see Naming and referencing containers, blobs, and metadata.

Set the level of public access to the container. The default level is Private (no anonymous access).

NoteIn the upload function, I am using my own blob storage connection string. But you will use your own blob storage connection string. Go to Access keys inside this tab you will get two keys (key1 and key2) with also connection strings. You can use either key1 or key2. In this demo we only need the connection string, so you will only copy the connection string.

public partial class MainPage : ContentPage

{

public MainPage()

{

InitializeComponent();

}

private MediaFile _mediaFile;

private string URL { get; set; }

//Picture choose from device

private async void btnSelectPic_Clicked(object sender, EventArgs e)

{

await CrossMedia.Current.Initialize();

if (!CrossMedia.Current.IsPickPhotoSupported)

{

await DisplayAlert("Error", "This is not support on your device.", "OK");