Google Cloud Storage - 如何访问存储桶内的静态资源等文件夹和文件 - Spring Boot

克里斯·斯瓦特

我想将 Google Cloud Storage 用于所有静态资源 - 图像等

该示例正在注入 1 个文件,但我想访问许多文件 - 给定一个名称

@Value("gs://${gcs-resource-test-bucket}/hello.txt")
private Resource gcsFile;

我也对迭代不感兴趣 - 因为我在存储桶中有文件夹,并且不想每次都迭代所有 100 个左右的文件

Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Page<Blob> blobs = storage.list(bucketName);

for (Blob blob : blobs.iterateAll()) {
  System.out.println(blob.getName());
}

有没有办法访问像 gs://somestringfilename 这样的文件?

不知道如何使用此属性来访问文件

You can also serve static resources by reading them from a bucket.
 spring.web.resources.static-locations=gs://p*

假设我有一个 rest 控制器来提供文件名,我如何从云存储中获取文件?

克里斯·斯瓦特

我使用 bean 解决了这个问题

StorageOptions.newBuilder().setProjectId(projectId).build().getService();

一个函数

私人页面文件夹(字符串目录前缀){

Page<Blob> blobs =
        storage().list(
            bucketName,
            Storage.BlobListOption.prefix(directoryPrefix));

return blobs;       

}

用法:directotyPrefix 不仅是我的文件夹,也是粘贴文件名

myfolder/ + 文件名withext

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用 Google Cloud Storage 将文件夹目标设置到存储桶中?

使用Webflux和Spring Boot搭配Google Cloud Storage上传MultiPart文件时出现UnsupportedOperationException

是否可以在Firebase / Google Cloud Storage存储桶上设置文件夹或存储桶级别的“ cacheControl”设置?

如何限制Google Cloud Storage存储桶的文件类型?

在运行时从 Google Cloud Storage 刷新 Spring 资源

在 Google Cloud Storage 中的项目/存储桶之间同步文件

我的Google Cloud Storage存储桶中的文件在哪里?

努力从 Google Cloud Storage 存储桶中读取 csv 文件

如何使用Google Cloud Function将文件从Cloud Storage存储桶中推送到实例中?

从Google Cloud Storage Bucket下载文件夹

从 Google Cloud Storage 中删除大文件夹

在Google Cloud Storage上还原存储桶

Google Cloud Storage 存储桶的扩展授权

从Google Cloud Function(Python)将新文件写入Google Cloud Storage存储桶

使用Google Cloud Console在Google Cloud Storage中的文件夹之间移动文件

将源文件存储在Google Dataproc HDFS与Google Cloud Storage(Google存储桶)中

如何从Google Cloud Storage下载文件并在Spring Controller中将其返回

使用Google Cloud Storage从Firebase存储中删除文件夹

如何使用JSON API和CloseableHttpClient将文件上传到Google Cloud Storage存储桶?

如何从Google Cloud Storage存储桶加载保存在joblib文件中的模型

如何使用PHP从Google Cloud Storage的存储桶中列出所有文件?

如何从Google Cloud Storage解密文件?

如何使用Node.js获取Google Cloud Storage文件夹中的文件列表?

如何使用 gsutil 将文件从 Google Cloud Storage 存储桶 1 复制到存储桶 2,同时保留 ACL

如何设置公共Google Cloud Storage存储桶

使用Google Cloud Dataflow合并Google Cloud Storage中的文件

Google Cloud SDK Python客户端:如何在Cloud Storage存储桶中列出文件?

从Google Cloud Storage流式传输文件

Google Cloud Storage加入多个csv文件