Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect or count Azure blob downloads?

Tags:

blob

azure

I have a software installer published as an Azure blob and I need to count how many times it has been downloaded.

The problem is that it can be referenced externally (from many download sites), therefore I cannot control it via website.

So... does Windows Azure have a mechanism to detect blob downloads or registers the count of them? Thanks!

like image 465
Néstor Sánchez A. Avatar asked Aug 03 '12 00:08

Néstor Sánchez A.


People also ask

How do I check my blob storage logs?

The diagnostics logs are saved in a blob container named $logs in your storage account. You can view the log data using a storage explorer like the Microsoft Azure Storage Explorer, or programmatically using the storage client library or PowerShell.

What is blob count?

This module simply counts the number of non-black pixel groups (blobs) within the current image.

How do I know if my Azure blob storage upload was successful?

If no exception throws from your code, it means the blob has been uploaded successfully. Otherwise, a exception will be thrown. You can also confirm it using any web debugging proxy tool(ex. Fiddler) to capture the response message from storage server.

How do I monitor my Azure storage account?

View from a storage accountIn the Azure portal, select Storage accounts. From the list, choose a storage account. In the Monitoring section, choose Insights.


2 Answers

You could use storage analytics to figure out how many downloads your blob has had:

Blob usage is also available as a graph in the new management portal:

enter image description here

like image 59
Richard Astbury Avatar answered Sep 23 '22 14:09

Richard Astbury


Did you ever consider to make your container private? This would prevent people from downloading blobs directly. By doing this you are in full control of who can download the files and for how long they can do this.

Let's assume only registered users can download the file and you're using ASP.NET MVC. Then you could have an action similar to this one:

    [Authorize]
    public ActionResult Download(string blobName)
    {
        CountDownload(blobName);

        var blobClient = storageAccount.CreateCloudBlobClient();
        var container = blobClient.GetContainerReference(containerName);
        var blob = container.GetBlobReference(blobname);

        var sas = blob.GetSharedAccessSignature
        (
          new SharedAccessPolicy
          {
              Permissions = SharedAccessPermissions.Read,
              SharedAccessStartTime = DateTime.Now.ToUniversalTime(),
              SharedAccessExpiryTime = DateTime.Now.ToUniversalTime().AddHours(1)
          }
        );

        return Content(blob.Uri.AbsoluteUri + sas);
    }

What this does is the following:

  • The Authorize attribute makes sure only users that are logged in can access this action.
  • You increase the download count for that blob
  • You get a reference of the blob based on the name
  • You generate a signature that allows downloading the blob for 1 hour
  • You return the url of the blob with the signature (you could also have it redirect to the blob url)

By handing out the URL with signature through your application you have full control and you can even look at other scenarios like CAPTCHA, paying downloads, advanced permissions in your application, ...

like image 41
Sandrino Di Mattia Avatar answered Sep 22 '22 14:09

Sandrino Di Mattia