How to detect or read Azure blob downloads?

I have an installer published as azure light, and I need to calculate how many times it has been downloaded.

The problem is that it can be referenced from the outside (from many download sites), so I canโ€™t control it through the website.

So ... does Windows Azure have a mechanism to detect blob downloads or register their number? Thanks!

+6
source share
2 answers

Have you ever considered your container to be personal? This will prevent people from directly loading drops. By doing this, you have full control over who can upload files and how long they can do it.

Suppose that only registered users can upload a file, and you are using ASP.NET MVC. Then you may have an action like this:

[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 does it mean:

  • The Authorize attribute allows only users who are logged in to access this action.
  • You increase downloads for this blob
  • You get a blob link based on name
  • You create a signature that allows you to download blob within 1 hour
  • You are returning the blob URL with the signature (you can also redirect it to the blob url)

By sending a signed URL through your application, you have full control, and you can even look at other scenarios like CAPTCHA, pay for downloads, advanced permissions in your application, ...

+9
source

You can use the storage analytics to find out how many downloads of your blob were:

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

enter image description here

+6
source

Source: https://habr.com/ru/post/922004/


All Articles