C#Google Cloud Storage获取文件夹中的ListObjects
我将所有应用程序信息存储在Google Cloud Storage中.我已经创建了一个存储桶,并在该存储桶中创建了文件夹.使用该代码,我可以获得所有文件夹的列表.
I'm storing all my application information in Google Cloud Storage. I've created a bucket and inside this bucket I've folders. With that code, I can get list of all my folders.
public static IList<uFolder> ListFolders(string bucketName)
{
if (storageService == null)
{
CreateAuthorizedClient();
}
Objects objects = storageService.Objects.List(bucketName).Execute();
if (objects.Items != null)
{
return objects.Items.
Where(x => x.ContentType == "application/x-www-form-urlencoded;charset=UTF-8").
Select(x => new uFolder(x.Name)).ToList();
}
return null;
}
但实际上,此代码将我所有的文件和文件夹放在存储桶中.所以我需要提取它们.我的第一个问题,是否有此方法的快捷方式?
But actually this code, get all my files and folders in my bucket. So I need to be extract them. My first question, Is there a shortcut to this method?
我的另一个最重要的问题是,如何将所有文件放在特定的文件夹中?例如; 我的存储桶名称为MyBucket,我想从"MyBucket/2/"中获取所有文件.我怎样才能做到这一点?这是检查文件的媒体链接或自链接的唯一方法吗?
My other and most important question is, How can I get all files just in specific folder? For example; My bucket name is MyBucket and I want to get all files from "MyBucket/2/". How can I do this? Is this the only way check the medialink or selflink of the files?
感谢所有答案.祝你有美好的一天,好作品...
Thanks for all answer. Have a good day, good works...
如果要在Google云端存储中获取顶级文件夹,则所有人都可以使用;
If want to get top folders in your Google Cloud Storage, everyone can use;
ObjectsResource.ListRequest request = storageService.Objects.List(CurrentBucket);
request.Delimiter = "/";
Google.Apis.Storage.v1.Data.Objects response = request.Execute();
if (response.Prefixes != null)
{
return response.Prefixes.ToList();
}
如果要在特定文件夹内获取文件夹;
If want to get folders inside specific folder;
ObjectsResource.ListRequest request = storageService.Objects.List(CurrentBucket);
request.Delimiter = "/";
request.Prefix = delimiter; //delimiter is any sub-folder name. E.g : "2010/"
Google.Apis.Storage.v1.Data.Objects response = request.Execute();
if (response.Prefixes != null)
{
return response.Prefixes.ToList();
}
注意::我返回覆盖率文件夹的前缀.
Attention : I'm returning Prefixes for reach folders.