DEV Community

Cover image for How to Setup Storage for a Public Website.
SULIAT
SULIAT

Posted on

How to Setup Storage for a Public Website.

what is a Public Website?

A public website is one that anyone in the world can open and browse without needing to sign in. Think of websites like Amazon, Temu, or Shein, you land on the page and you immediately see products, photos, videos, and reviews. No login required, that is what makes them "public." For a website like this to work well, the images, videos, and customer stories it shows must be stored somewhere reliable, fast, and accessible to everyone.
That "somewhere" is called a Storage Account. The storage account holds everything the website needs to display, and it makes those files available to anyone who visits the site, wherever they are in the world.

In this article, I will show you how to set up a storage account for a public website. By the time we are done, you will know exactly how to get your content online, keep it accessible to everyone, and protect it from accidental loss. To get there, we will be working through the following five steps:

1. Create a storage account with high availability:

Since customers are located worldwide and demand is rapidly growing, we need this storage account to be set up with high availability. This means the storage account is built to stay online and keep serving content even if something goes wrong on one server.
a) Create a storage account to support the public website.

  • In the portal, search for and select Storage accounts. search and select
  • Select + Create.

+ create

  • For resource group select new. Give your resource group a name and select OK.

resource group

  • Set the Storage account name to publicwebsite. Make sure the storage account name is unique by adding an identifier.

storage accounts

  • Take the defaults for other settings.

defaults

  • Select Review and then Create.

select

  • Wait for the storage account to deploy, and then select Go to resource.

go to
b) This storage requires high availability if there’s a regional outage. Additionally, enable read access to the secondary region.

  • In the storage account, in the Data management section, select the Redundancy blade.

data

  • Ensure Read-access Geo-redundant storage is selected.

Rea

  • Review the primary and secondary location information.

location
c) Information on the public website should be accessible without requiring customers to login.

  • In the storage account, in the Settings section, select the Configuration blade.

configuration

  • Ensure the Allow blob anonymous access setting is Enabled.

blob

  • Be sure to Save your changes.

save

2. Create a blob storage container with anonymous read access:

With the storage account ready and open to the public, the next step is to create a container inside it, and this step is non-negotiable. You cannot just throw files loosely into a storage account. Containers are used for storing Blobs. Think of the storage account as a fridge and the container as the bowl you put food into before placing it in the fridge that way everything stays neat, organized, and easy to find. Without the bowl, everything is a mess and hard to manage. A blob storage container works exactly the same way. The container keeps Blobs organized and structured.
a) The public website has various images and documents. Create a blob storage container for the content.

  • In your storage account, in the Data storage section, select the Containers blade.

containers

  • Select + Container.

+ container

  • Ensure the Name of the container is public.

name

  • Select Create.

create
b) Customers should be able to view the images without being authenticated. Configure anonymous read access for the public container blobs.

  • Select your public container.

public

  • On the Overview blade, select Change access level.

access

  • Ensure the Public access level is Blob (anonymous read access for blobs only).

read access

  • Select OK.

ok

3. Practice uploading files and testing access.

a) For testing, upload a file to the public container. The type of file doesn’t matter. A small image or text file is a good choice.

  • Ensure you are viewing your container.

views

  • Select Upload.

uploaD

  • Browse to files and select a file. Browse to a file of your choice.

browse

  • Select Upload.

click

  • Close the upload window, Refresh the page and ensure your file was uploaded. photo b) Determine the URL for your uploaded file. Open a browser and test the URL.
  • Select your uploaded file.

file

  • On the Overview tab, copy the URL.

Log

  • Paste the URL into a new browser tab.

google

  • If you have uploaded an image file it will display in the browser. Other file types should be downloaded.

step 3b

4. Configure soft delete:

Accidents happen. Someone might delete an important product image or video by mistake. Soft delete is a safety feature that makes sure a deleted file is not gone forever. Instead, when a file is removed, the system quietly holds onto it in the background for a set number of days. During that time, you can go back and restore it with just a few clicks. It is like retrieving something from the recycling bin before it is permanently emptied. I will show you the steps on how to enable and retrieving soft delete for blobs.
a) It’s important that the website documents can be restored if they’re deleted. Configure blob soft delete for 21 days.

  • Go to the Overview blade of the storage account. overview
  • On the Properties page, locate the **Blob service **section.

service

  • Select the Blob soft delete setting.

soft

  • Ensure the Enable soft delete for blobs is checked.

Enable

  • Change the Keep deleted blobs for (in days) setting to 21.

Change

  • Notice you can also Enable soft delete for containers.

notice

  • Don’t forget to Save your changes.

changes
b) If something gets deleted, you need to practice using soft delete to restore the files.

  • Navigate to your container where you uploaded a file.

navigate

  • Select the file you uploaded and then select Delete.

delete

  • Select OK to confirm deleting the file. step 4b
  • On the container Overview page, toggle the slider Show deleted blobs. This toggle is to the right of the search box.

overview

  • Select your deleted file, and use the ellipses on the far right, to Undelete the file.

undelete

  • Refresh the container and confirm the file has been restored.

refresh

5. Configure blob versioning:

The final step is enabling versioning. Versioning means that every time we update a file, the old version is saved too. you always have a history of your files and can go back to an older version at any time if something goes wrong.
a) It’s important to keep track of the different website product document versions.

  • Go to the Overview blade of the storage account.

step 5a

  • In the Properties section, locate the Blob service section.

Properties

  • Select the Versioning setting.

Versioning

  • Ensure the Enable versioning for blobs checkbox is checked.

Enable

  • Notice your options to keep all versions or delete versions after.

options

  • Don’t forget to Save your changes.

don't forget
b) As you have time experiment with restoring previous blob versions.

  • Upload another version of your container file. This overwrites your existing file.

Another version

  • Your previous file version is listed on Show deleted blobs page.

Previous

By following the steps outlined in this guide, you have now built a storage setup that is fully functional, secure, ready to power a real, live, public website. Starting from creating a high-availability storage account, all the way through to enabling soft delete and versioning.

Top comments (0)