【问题标题】:How to get Azure Blob file size如何获取 Azure Blob 文件大小
【发布时间】:2014-10-06 12:53:37
【问题描述】:

我使用 Azure blob 存储图像。用户上传这些图像。我想看看每个用户的图片占用了多少空间。我怎样才能在 ASP.NET 代码中做到这一点?我可以通过知道它的 URI 来获得图像文件的大小吗?还是我需要使用一些与 blob 相关的功能?

【问题讨论】:

    标签: asp.net azure-blob-storage


    【解决方案1】:

    您需要先获取 blob 的属性。例如,

    var blob = _container.GetBlockBlobReference(blobName);
    if (blob.Exists())
    {
        blob.FetchAttributes();
        return blob.Properties.Length;
    }
    
    throw new Exception("Blob doesn't exist");
    

    【讨论】:

      【解决方案2】:

      在这里回答 scala/java,以防有人被卡住。为了获得 blob 的大小,您可以使用以下代码:

      val blob: CloudBlockBlob = container.getBlockBlobReference(blobPath)
      blob.downloadAttributes()
      blob.getProperties.getLength
      

      确保您确实调用了 downloadAttributes,否则属性将为空。

      您可以参考此文档了解更多详细信息 https://docs.microsoft.com/en-us/java/api/com.microsoft.azure.storage.blob.cloudblockblob?view=azure-java-legacy

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-07
        • 2021-06-13
        • 2013-02-11
        • 1970-01-01
        • 2015-09-16
        • 1970-01-01
        • 2020-09-23
        • 2019-03-22
        相关资源
        最近更新 更多