How to Use Blob Storage via Azure File Storage

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

Blob storage has a number of features that are usually not available in the other two types of file systems, namely standard hard drives and Microsoft Azure File Storage. These features include scalability, agility and easy collaboration across multiple users.

Blob Storage is a cloud-based storage service that allows users to store large files on the internet. Azure File Storage is Microsoft’s implementation of Blob Storage. It allows you to upload, download, and manage your files from any device with an internet connection. Read more in detail here: azure blob storage.

How to Use Blob Storage via Azure File Storage

You may find yourself in need of a low-cost, high-efficiency storage solution at some time, but where do you look for it? Take a look at the Binary Large Object (blob) storage in Microsoft Azure! Blob storage is an Azure storage solution that allows you to store and distribute massive volumes of text and binary data files, streaming information, and even static material.

By stepping through several popular cases, you’ll learn how to interact with blob storage in Azure in this article.

Continue reading to get started!

Prerequisites

This will be a hands-on presentation in this course. Make sure you have the following installed and ready to go if you want to follow along.

You Have a Few Options for Getting Free Microsoft Azure

Putting Together an Azure Environment

You must first import PowerShell Core modules, connect to your Azure Subscription, and create an Azure environment before you can use blob storage to store your files.

1. Run the following command in PowerShell 7 to import the modules you’ll need to store files in blob storage.

Adding the required modules Adding the required modules

# Az.Accounts – Provides credential management cmdlets # Az.Resources – Provides top-level Azure resource providers, such as subscriptions, using cmdlets. # Az.Storage – This package contains cmdlets for working with various storage resources, like as blobs. Az.Accounts, Az.Resources, and Az.Storage Import-Module

2. Log in to your Azure Active Directory (AD) tenancy, then enter the command below in your web browser to complete an interactive authentication, as seen below.

Other authentication techniques, such as utilizing a Service Principal or an access token, are outside the scope of this article.

Login to Azure Portal using the interactive login feature.Login to Azure Portal using the interactive login feature.

Always double-check that the tenant and subscription shown after signing in are the ones you want to use. You have the option to modify your context if necessary.

3. Now execute the command below to establish a new resource group named demo, with five random numbers attached to it (Get-Random -Maximum 99999). Subscriptions are hierarchically below resource groups, which include resources for more detailed control.

For this example, the resource group’s -Location is set to Central US. When the command is finished, the result is saved in the $resourceGroup variable.

$resourceGroup = New-AzResourceGroup; $resourceGroup = New-AzResourceGroup; $resourceGroup = “demonstration Get-Random -Maximum 99999 $(Get-Random -Maximum 99999) “-‘Central United States’ as a location

Putting together a new resource group Putting together a new resource group

4. To execute the following activities and establish a new Azure storage account, use the command below. The storage account in this example is called storage, and it has five random numbers applied to it (Get-Random -Maximum 99999). After the command completes, the resulting object will be stored in the $storageAccount variable.

# Replace the ResourceGroupName property of the $resourceGroup variable you defined in step three with the -ResourceGroupName. # Create a storage account with a name identical to the resource group and append random numbers to it. # Use the same -Location as the Location property of the $resourceGroup variable. # It’s a good idea to put resources in the same area as the parent resource group. # Use either # locally redundant storage (LRS) or a globally unique name inside Azure to provide the storage account name -SkuName. ‘ -ResourceGroupName $resourceGroup.ResourceGroupName’-Name storage $storageAccount = New-AzStorageAccount a dollar (Get-Random -Maximum 99999) ‘ -SkuName Standard LRS’-Location $resourceGroup.Location

The process of creating a new storage account The process of creating a new storage account

5. Run the following command to complete a few activities related to the Azure AD Role assignment:

  • Using the UserID property given by the Get-AzAccessToken cmdlet, the -SignInName value utilizes the account you’re currently signed in with.
  • The Storage Blob Data Contributor built-in role you’re assigning is the value of -RoleDefinitionName.
  • The -Scope value, which is specified through the $storageAccount variable’s Id property, determines the scope of the role assignment for the storage account you established (storage10029 in the example below).

As needed, you may provide more granular role assignments to particular containers.

-SignInName New-AzRoleAssignment (Get-AzAccessToken). -Scope $storageAccount.Id -RoleDefinitionName “Storage Blob Data Contributor”‘ UserId’ -RoleDefinitionName “Storage Blob Data Contributor”‘

Making and checking a new file Making and checking a new file

6. Finally, execute the programs listed below to generate a temp.dat file on your local system. To show how blob storage works, you’ll upload and retrieve this file from the storage account in the next steps.

$file = New-Object System.IO.FileStream.temp.dat,Create,ReadWrite $file = New-Object System.IO.FileStream.temp.dat,Create,ReadWrite $file = New-Object System.IO.FileStream.temp.dat,Create,ReadWrite $file # Set the file’s size to $file. SetLength(10MB) # Delete the $file handle. Close() # Use Get-ChildItem $file.Name to validate the file’s size. Length

Making and checking a new fileMaking and checking a new file

Using PowerShell to Upload Files

Let’s get started uploading the file to blob storage now that you’ve set up an Azure setup and prepared a sample file. Blob storage differs from traditional filesystems. Each file in the blob storage is a container that contains an object.

Blobs’ essential functionality is comparable to that of other filesystems, yet in certain circumstances, either might be a superior fit. Blobs may also serve as a backup for virtual filesystems (e.g., BlobFuse).

PowerShell, AzCopy, and the Azure Portal are all options for uploading files to your storage accounts. But first, let’s use PowerShell to upload the example file (temp.dat) to blob storage. When working with your Azure Storage Accounts, PowerShell provides a uniform experience.

The activities necessary to complete this demo will cost money. Keep track of your use and eliminate resources that you don’t plan to utilize.

To create a new container, use the instructions below and upload the temp.dat file ($file) as an object. For this example, the container is called demo, but you may call it anything you like.

# Creates a container within $storageAccount using the Context property of the storage account # The returned object is then passed to the $container variable $container = New-AzStorageContainer -Name demo -Context $storageAccount.Context # Uploads the temp.dat file ($file) to the demo container ($container) # The blob name (-Blob) will use the same name as the file you’re uploading (Get-Ch

A file is uploaded to an Azure Storage Account. A file is uploaded to an Azure Storage Account.

How to Use PowerShell to Copy Files to Azure Blob Storage

Using AzCopy to Upload Files

Perhaps you have more complicated use cases in mind, such as syncing material or replicating content across many accounts at scale. If that’s the case, you’ll require the AzCopy command-line utility.

To connect to your Azure tenancy, use the instructions below to transfer your local file ($file) to the URL endpoint of your container. Because AzCopy is unaware of the credentials you’re using with PowerShell, you’re signing in to Azure tenancy.

# Login to the Azure tenant & .azcopy.exe login # Copy the local $file to the full URI of the destination $container & .azcopy.exe copy $file.Name $container.CloudBlobContainer.Uri.AbsoluteUri

Using AzCopy to upload to an Azure Storage Account Using AzCopy to upload to an Azure Storage Account

Instead of uploading, perhaps you want to download files via AzCopy. If so, run the command below to copy the specified files (temp.dat) from your container to the current local directory: & .azopy.exe copy “$($container.CloudBlobContainer.Uri.AbsoluteUri)/temp.dat” .temp.dat

How To Use AZCopy To Manage Files Between Local And Azure Storage

Using the Azure Portal to Upload Files

Azure Storage Explorer is your buddy if you prefer a GUI approach of uploading your files. One of the greatest graphical techniques for managing your blob storage is Azure Storage Explorer. The storage explorer may be accessed using the Azure Portal’s storage account resource.

1. Open your preferred web browser and go to Azure Portal’s Storage Explorer.

2. Access the Upload blob blade by clicking on the demo container under BLOB CONTAINERS, as shown below (right panel).

3. Select which files to upload by clicking the folder icon in the Upload blob window (temp.dat).

4. Finally, to submit your file, click Upload (blue button).

In Azure Storage Explorer, use the Upload blob blade. In Azure Storage Explorer, use the Upload blob blade.

When the upload is finished, close the Upload blob blade to view your uploaded blob, as seen below.

In Azure Storage Explorer, you may see the contents of a blob container. In Azure Storage Explorer, you may see the contents of a blob container.

Using the Azure Portal to Download Files

Similar to posting files to blob storage, Azure allows you to get files in a variety of methods. However, because you just uploaded a file (temp.dat) using Azure Portal, let’s get the same file via Azure Storage Explorer.

In the Azure Storage Explorer, choose the file (temp.dat) to download and click the Download button, as shown below. This will bring up a new dialog box where you may approve the download that you’ll see in the following step.

Choosing Which Files to Download Choosing Which Files to Download

To download the files you chose, click the Click here to begin downloading option.

Selecting Files from the Blob Storage and Downloading Them Selecting Files from the Blob Storage and Downloading Them

Using PowerShell to Download Files

You can get files from the blob storage using PowerShell commands, just as you can post them. You may list the items in a container and then download them using PowerShell.

To list all items in your container and download temp.dat to your local directory, use the instructions below.

# Get-AzStorageBlob -Container $container Get-AzStorageBlob -Container $container Get-AzStorageBlob -Container $container Get-AzStorageBlob -Container $container Get-AzStorageBlob -Con -Context $storageAccount.Context $storageAccount.Context $storageAccount.Context $storageAccount.Con # Get the temp.dat object from the $container variable. -Blob temp.dat -Container $container Get-AzStorageBlobContent -Context $storageAccount.Context $storageAccount.Context $storageAccount.Context $storageAccount.Con

Files are being downloaded from an Azure Storage Account. Files are being downloaded from an Azure Storage Account.

You may establish a preauthorized download link using Shared Access Signature (SAS) tokens if you wish to utilize short-lived unique URLs to download files. These tokens are one-of-a-kind, private identification tokens that may be used to confirm your identity.

To generate a new download link for the file (temp.dat) you wish to download, run the instructions below. After 10 seconds, the created download link expires, and the material is downloaded (Invoke-WebRequest $uri) to the $temp variable.

# Create a new download link that will expire in 10 minutes. -Context $uri = New-AzStorageBlobSASToken -Container $storageAccount.Context -Blob temp.dat $container.Name -ExpiryTime -Permission r (Get-Date). -FullUri -AddSeconds(10) # Download the file to the $temp variable via the URL. # Alternatively, write the file to the current directory using $temp = Invoke-WebRequest $uri. $url -OutFile.temp.dat Invoke-WebRequest

Using an SAS token, download from an Azure Storage Account. Using an SAS token, download from an Azure Storage Account.

Blob Storage allows you to host a web page on the public internet.

You’ve seen use cases of authorized users downloading files up to this point. Did you realize, however, that blob storage may also be a great solution for public content? Using a blob to house your web page content is one approach, which you’ll see in this video.

Even though the contents of your web page are encrypted in transit and at rest, if public access is enabled, anybody may view them.

Because you’re creating a new use case, you’ll take advantage of one of the public cloud’s biggest advantages: size and elasticity. You may create a separate storage account for a particular use case and reduce the danger of utilizing public containers by doing so.

1. Run the command below to create a new storage account as you did in step four of the “Putting Together an Azure Environment” section. But this time, you’ll pass the returned object to the $publicStorageAccount variable.

New-AzStorageAccount -ResourceGroupName $resourceGroup.ResourceGroupName -Name storage $publicStorageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroup.ResourceGroupName -Name storage a dollar (Get-Random -Maximum 99999) -Location -SkuName Standard LRS $resourceGroup.Location

Creating an account for storage Creating an account for storage

You now have a dedicated storage account for your public content, which you can use with the following command to host static web content.

2. Next, use the Enable-AzStorageStaticWebsite cmdlet to set up your new use case’s storage account ($publicStorageAccount). The -IndexDocument option specifies the default web page that users will see. The -Context will be the newly formed storage account.

# Set up the storage account and create the $web container. -IndexDocument index.html -Context Enable-AzStorageStaticWebsite $publicStorageAccount.Context

For website hosting, enable the storage account. For website hosting, enable the storage account.

3. Use the instructions below to generate a new HTML page in your current directory and upload it to the container dedicated to web content hosting. So that web browsers can correctly comprehend the page, the content type is set to HTML (ContentType=”text/html”).

Accessing the document on a web browser prints the Hello from <storage account name> message.

# Create a simple HTML file “<body><h1>Hello from $($publicStorageAccount.StorageAccountName)!</h1></body>”|Out-File .index.html # Upload the HTML file to the static web hosting container and set the ContentType to text/html Set-AzStorageBlobContent -File .index.html -Container “`$web” -Properties @{ContentType=”text/html”} -Context $publicStorageAccount.Context

Make an HTML document and upload it. Make an HTML document and upload it.

4. Now execute the command below to obtain the URL where your content may be accessed by people.

$publicStorageAccount.PrimaryEndpoints.Web

Get the endpoint's URI. Get the endpoint’s URI.

5. Finally, open the URL in your browser, and you should see something like the picture below.

Using Blob Storage to Access HTML Documents Using Blob Storage to Access HTML Documents

Organizing Resources

You’ll want to clear up your resources now that you’ve gone through the process of evaluating these new blob storage techniques. Why? You’ll be able to maintain your membership clean if you do so. More significantly, you will no longer be subjected to extra fees.

Because you utilized all of the resources in this lesson in a single resource group, you may delete the resource group and clear away all of the resources.

Because resources aren’t always confined inside a single resource group, it’s important to employ logical segmentation liberally, particularly when testing or iterating regularly.

To destroy the resource group and all resources inside it, use the Remove-AzResourceGroup cmdlet below, supplying the ResourceGroupName property of the $resourceGroup variable.

-Name Remove-AzResourceGroup $resourceGroup.ResourceGroupName

Delete the resource group as well as its contents. Delete the resource group as well as its contents.

Conclusion

You’ve learned how to upload and download files to and from blobs in cloud storage on several platforms in this lesson. You’ve also learned that blob storage can be used to host a web page that visitors may see openly.

With blob storage and other storage types, you can do a lot more, so how would you expand on these ideas? Perhaps work with Azure virtual machines’ file storage accounts, offer serverless file systems, or employ page blobs for virtual hard disks?

The “blob storage vs file storage” is a question that has been asked before. Blob storage is a type of cloud storage that offers more features than file storage does.

Related Tags

  • azure blob storage documentation
  • azure storage explorer
  • azure blob storage explorer
  • azure blob storage api
  • how to create blob storage in azure

Table of Content