【问题标题】:Size of a file stored at azure file service存储在 azure 文件服务中的文件的大小
【发布时间】:2017-11-18 00:42:51
【问题描述】:

我的文件存储在 Microsoft Azure 文件服务中。

问题

如何获取文件的大小?

【问题讨论】:

  • 先导入 azure 库...开始编码!
  • 你试过什么? Azure 文件存储作为 SMB 附加并允许您使用普通文件 I/O。

标签: python azure


【解决方案1】:

我找到了一个特定于文件并返回确切大小的 Python 解决方案:

file_properties = file_service.get_file_properties(share_name, directory_name, file_name)
file_size = file_properties.properties.content_length

如果您想了解更多信息,请尝试运行:

file_properties.__dict__.keys()
file_properties.properties.__dict__.keys()

输出:

dict_keys(['name', 'content', 'properties', 'metadata'])
dict_keys(['last_modified', 'etag', 'content_length', 'content_range', 'content_settings', 'copy', 'server_encrypted', 'smb_properties', 'lease'])

删除 .keys() 以在字典中输出值。

Python SDK 文档:

get_file_properties(): https://azure-storage.readthedocs.io/ref/azure.storage.file.fileservice.html#azure.storage.file.fileservice.FileService.get_file_properties

models.File 属性: https://azure-storage.readthedocs.io/ref/azure.storage.file.models.html#azure.storage.file.models.File

models.FileProperties 属性: https://azure-storage.readthedocs.io/ref/azure.storage.file.models.html#azure.storage.file.models.FileProperties

【讨论】:

    【解决方案2】:

    请参阅以下文档以通过 python 列出文件共享中的文件: https://docs.microsoft.com/en-us/azure/storage/files/storage-python-how-to-use-file-storage#list-shares-and-snapshots

    您还可以通过 Azure 门户和 PowerShell 查看上传文件的大小

    Portal签入路径:存储账户>点击存储账户>文件服务>文件共享

    使用 PowerShell:https://docs.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-powershell#list-the-files-in-the-directory

    【讨论】:

    • 谢谢大家的回复,这个有效:file_service.get_share_stats("myShareName") 唯一没有返回确切大小的东西,它将大小四舍五入到最接近的千兆字节。跨度>
    【解决方案3】:

    根据我的经验,您可以尝试通过以下方式获取文件的大小。

    Azure 门户:

    登录门户,直接查看

    Microsoft Azure 存储资源管理器:

    登录工具,直接查看

    请从here下载工具。

    Python SDK:

    获取共享大小的用户共享状态方法。

    file_service.get_share_stats("myshare")
    

    或者您可以获取文件的字节并计算大小。

    System.out.println("File size in bytes is: " + fileSize);
    System.out.println("File size in KB is : " + (double)fileSize/1024);
    System.out.println("File size in MB is :" + (double)fileSize/(1024*1024));
    

    下载文件:

    下载文件到本地并检查文件大小。

    file_service.get_file_to_path('myshare', None, '1.png', 'out.png')
    

    你也可以参考这个帖子: How to get or calculate size of Azure File/Share or Service

    【讨论】:

    • 谢谢大家的回复,这个有效:file_service.get_share_stats("myShareName") 唯一没有返回确切大小的东西,它将大小四舍五入到最接近的千兆字节。跨度>
    • @Anmar 是的,那么您可以通过最近的千兆字节计算共享大小。或者您可以直接通过门户或 Microsoft Azure Storage Explorer 工具查看文件的大小。如果你觉得我的回答对你有用,可以在论坛上标记答案供其他人参考。谢谢。
    【解决方案4】:

    谢谢大家的回复,

    这个有效:

    file_service.get_share_stats("myShareName")

    它唯一没有返回确切大小的地方,它将大小四舍五入到最接近的千兆字节。

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 2017-10-23
      • 1970-01-01
      • 2014-12-03
      • 2021-08-07
      • 1970-01-01
      • 2020-02-14
      • 1970-01-01
      • 2015-03-08
      相关资源
      最近更新 更多