英文:
Is it possible to query multiple files with one request in Google Cloud Storage?
问题
我有一个函数用于检索存储在Google Cloud Storage中对象的下载链接。在Java中的实现大致如下:
public String getDownloadLink(String bucketName,
String blobName) {
return storage.signUrl(
BlobInfo.newBuilder(bucketName, blobName).build(),
60,
TimeUnit.MINUTES,
SignUrlOption.httpMethod(HttpMethod.GET),
SignUrlOption.withV4Signature()
).toString();
}
上述方法接受bucketName
和blobName
作为参数,并返回一个有效期为60分钟的对象下载链接。是否有可能使用Java客户端API for GCS获取同一存储桶中多个文件或对象的下载链接列表,而无需在for循环中调用上述函数?例如,上述方法可能如下:
public List<String> getDownloadLink(String bucketName,
List<String> blobName) {
// 获取列表中所有blobName的下载链接
}
我一直在寻找解决方案,但未能找到实质性的内容,一直在使用for循环获取多个文件的下载链接。使用for循环查询多个文件可能会消耗大量资源并且很繁琐。真的需要一些帮助。
英文:
I have a function that retrieves a download link for an object stored in the Google Cloud Storage. The implementation in Java looks something like this:
public String getDownloadLink(String bucketName,
String blobName) {
return storage.signUrl(
BlobInfo.newBuilder(bucketName, blobName).build(),
60,
TimeUnit.MINUTES,
SignUrlOption.httpMethod(HttpMethod.GET),
SignUrlOption.withV4Signature()
).toString();
}
The above method takes the bucketName
and blobName
as arguments and returns a downloadlink for that object, valid for 60 minutes. Is it possible to get a list of downloadlink for multiple files or objects in the same bucket, using Java client api for GCS, without having to call the above function in a for-loop? For example the above method could look something like :
public List<String> getDownloadLink(String bucketName,
List<String> blobName) {
// Get the downloadlinks for all the blobName in the list
}
I've been looking around for a solution, but couldn't find anything substantial, and been resorting to using a for-loop to get downloadlinks for multiple filenames. Using for-loop to query multiple files could get pretty resource consuming and tedious. Could really use some help.
答案1
得分: 1
根据我对问题的理解,您希望为存储桶中的多个对象返回一组有效期为60分钟的已签名 URL(而不是直接下载文件)。
显然,如果您要使用任何云存储客户端库下载这些对象,您可以使用 BlobListOption.prefix()
来在特定文件夹或对象上过滤查询,就像这个 示例代码 中所示。
然而,在查阅了 Java 云存储客户端库的 文档 后,我目前不知道任何基于前缀或方法的已签名 URL,可以用于访问 Cloud Storage API 中对象列表。
由于每个文件或对象都需要单独签名,您很可能需要遍历对象列表。
虽然这不是 Java 云存储客户端库,但我找到了以下 示例,可能会对您有所帮助。
英文:
Based on my understanding of the question, you want to return a list of signed URLs (valid for 60 min) for multiple objects within a bucket, not directly downloading the files.
It is evident that if you were to download these objects using any of the Cloud Storage client libraries, you could use BlobListOption.prefix()
to filter the query on certain folders or objects, as shown in this example code.
However, after checking the Java Cloud Storage client library documentation, I'm not aware of any prefix or method based Signed URL to access a list of objects in Cloud Storage API at the moment.
Since every file or object needs to get signed individually, you will most likely need to iterate through the list of blobs.
Although it is not the Java Cloud Storage client library, I found the following example that may help you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论