Drive SDK获取文件夹大小 [英] Drive SDK Get Folder Size

查看:121
本文介绍了Drive SDK获取文件夹大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用'quotaBytedUsed'属性,同时使用授权get获取文件请求 - Files.list



我将获得的长整型值转换为KB / MB / Gb的文件大小。

然而,所有文件夹的大小都是1 KB 。此值并不反映文件夹中所有内容大小的总和。



如何获得这笔金额(如果可能,不需要额外的服务器请求) ?



用于将'quotaBytesUsed'转换为文件大小的代码是

  private string [] SizeSuffixes = new [] {B,KB,MB,GB,TB}; 

private string SizeConvert(long?fileSize)
{
if(!fileSize.HasValue)
return;

var size = fileSize.Value;

if(size< = 1024)
{
return1 KB;
}

var suffixIndex = 0;

while(size&> 1024)
{
size = size / 1024;

suffixIndex ++;
}

return size.ToString(CultureInfo.InvariantCulture.NumberFormat)++ SizeSuffixes [suffixIndex];


解决方案

该文件夹对象,而不是其内容。
api不支持获取文件夹内容的大小。



鉴于相同的文件/文件夹可以放在多个文件夹中,我怀疑它会被支持。



您需要递归计算它,例如使用appengine任务队列。


I am using 'quotaBytedUsed' property while getting Files using an authorized get request - Files.list.

I am converting the long value obtained to file size in KB/MB/Gb as appropriate.

However, size of all folders obtained is 1 KB. This value doesn't reflect the sum total of sizes of all content in the folder.

How can I get the this sum ( if possible without any extra request to server )?

Code used for converting 'quotaBytesUsed' to file size is

private string[] SizeSuffixes = new[] { "B", "KB", "MB", "GB", "TB" };

private string SizeConvert(long? fileSize)
    {
        if (!fileSize.HasValue)
            return "";

        var size = fileSize.Value;

        if (size <= 1024)
        {
            return "1 KB";
        }

        var suffixIndex = 0;

        while (size > 1024)
        {
            size = size / 1024;

            suffixIndex++;
        }

        return size.ToString(CultureInfo.InvariantCulture.NumberFormat) + " " + SizeSuffixes[suffixIndex];
    }

解决方案

You are getting the size of the folder object, not its contents. The api doesnt support getting a folder content's size.

Given that the same file/folder can be in multiple folders, I doubt it will ever be supported.

You need to recursively calculate it, using appengine task queues for example.

这篇关于Drive SDK获取文件夹大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆