获取云存储(Java)中的文件列表 [英] Get list of files in Cloud Storage (Java)

查看:91
本文介绍了获取云存储(Java)中的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用GAE SDK列出我的Google Cloud Storage存储分区中的所有文件?我知道Python SDK支持这样的功能,但是在Java SDK中找不到类似的功能。



如果不可用,是否将添加到Java SDK的未来版本?

解决方案

您可以通过其客户端库。一旦你设置了你的凭证,你可以这样调用:

  Storage storage = new Storage(httpTransport,jsonFactory,credential) ; 
ObjectsList list = storage.objects().list(bucket-name)。execute();
for(Object obj:list.getItems()){
// ...
}

在这种情况下,您可能还想使用 AppIdentityCredential ,这将允许存储桶归您的应用程序所有,而不是一位用户。

Is there any possibility to list all files on my Google Cloud Storage bucket with the GAE SDK? I know that the Python SDK supports such a function, but I can't find a similar function in the Java SDK.

If not available, will this be added in the future releases of the Java SDK?

解决方案

You can use the Cloud Storage JSON API via its client library. Once you set up your credentials you can make the call like this:

Storage storage = new Storage(httpTransport, jsonFactory, credential);
ObjectsList list = storage.objects().list("bucket-name").execute();
for (Object obj : list.getItems()) {
  //...
}

You may want to use an AppIdentityCredential in this case as well, which will allow the bucket to be owned by your application, and not by a user.

这篇关于获取云存储(Java)中的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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