如何检测或计算Azure

如何检测或计算Azure

本文介绍了如何检测或计算Azure Blob下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发布为Azure blob的软件安装程序,我需要计算它已被下载了多少次.

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.

那么... Windows Azure是否具有检测Blob下载或注册计数的机制?谢谢!

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

推荐答案

您是否曾经考虑过将容器设为私有?这样可以防止人们直接下载Blob.这样,您可以完全控制谁可以下载文件以及他们可以下载文件的时间.

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.

假设只有注册用户可以下载文件,并且您正在使用ASP.NET MVC.然后,您可能会执行与该操作类似的操作:

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);
    }

它的作用如下:

  • Authorize属性可确保只有登录的用户才能访问此操作.
  • 您增加了该Blob的下载数量
  • 您会基于名称获得blob的引用
  • 您生成一个签名,该签名允许1个小时的时间下载该blob
  • 您返回带有签名的Blob的网址(也可以将其重定向到Blob的网址)

通过在应用程序中分发带有签名的URL,您可以完全控制,甚至可以查看CAPTCHA,支付下载费用,在应用程序中具有高级权限等其他情况,...

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

这篇关于如何检测或计算Azure Blob下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:43