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
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:
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:
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, ...