Secure Download files in Azure Blob Storage

You saved customer order pdf files in azure blob storage blob and want to show these files on your e-commerce website.

But when files render on HTML its link should be deactivated means no one can use that link to download the file again.

Is this possible in Virto Commerce? Yes, it’s possible.

Virto Commerce works with Azure Blob Storage. You can upload customer order pdf files in a private container. Azure Blob Storage supports ‘SharedAccessBlobPolicy’ and you can create temporary access.

Here the sample code which demonstrates how to create Temporary Uri for a specific period (for example 1 minute).

After this period, the client will see AuthenticationFailed error: Signed expiry time […] must be after signed start time […].

        CloudStorageAccount account = CloudStorageAccount.Parse("your_Connection_String");
        CloudBlobClient serviceClient = account.CreateCloudBlobClient();

        var container = await serviceClient.GetContainerReference("your_Container_Name");
        container
            .CreateIfNotExistsAsync();

        CloudBlockBlob blob = container.GetBlockBlobReference("your_File_Path");

        SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();

        // Step 1. Define the expiration time. Ex: 1 minute.
        policy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1);

        // Step 2. Define the permission
        policy.Permissions = SharedAccessBlobPermissions.Read;

        // Step 3. create signature
        string signature = blob.GetSharedAccessSignature(policy);

        // Step 4. Get full temporary uri
        string fullTemporaryUri = blob.Uri + signature;

1 Like

You also can use SharedAccessStartTime from policy. This option very helpful when you wanna set up an access interval (e.x.: for the marketing campaign).

1 Like