java - 将文件直接上传到 Google Cloud Storage for GAE 应用程序

标签 java google-app-engine google-cloud-storage

我正在考虑从 Blobstore 切换到 Google Cloud Storage,以便在项目中上传图片(因为 Google 称 Blobstore 为“已取代”)。

在 Blobstore 中,多部分表单将直接提交(上传)到 Blobstore,然后 Blobstore 将重写请求并重定向到 GAE 应用程序以处理 BlobKey(s)。这意味着 GAE 应用程序的负载非常小。

有没有办法通过 Google Cloud Storage (GCS) 实现类似的工作流程?

Reading and Writing to Google Cloud Storage 给出的示例涉及处理上传、读取数据并将其保存在 GCS 中的 GAE 代码。

类似地为(例如)上传的图像文件提供服务:似乎必须在一个人的 GAE 代码中实现一个处理程序才能从 GCS 读取并返回图像数据。

有没有一种方法可以简单地为 GCS 中的资源生成一个 URL(AFAIK AWS S3 支持这个)并让它从那里提供服务?

最佳答案

您可以继续使用 blobstore API,但在 GCS 中使用实际存储,这意味着相同的上传行为并且可能对您的应用进行最小的更改。

来自 Using the Blobstore API with Google Cloud Storage (Python) :

You can use the Blobstore API to store blobs in Cloud Storage instead of storing them in Blobstore. You need to set up a bucket as described in the Google Cloud Storage documentation and specify the bucket and filename in the blobstore.blobstore.create_upload_url gs_bucket_name parameter. In your upload handler, you need to process the returned FileInfo metadata and explicitly store the Google Cloud Storage filename needed to retrieve the blob later.

那里还提供了一个完整的示例应用程序。

更新:糟糕,上面的答案适用于Python环境,Java环境如下:

来自 Using the Blobstore API with Google Cloud Storage (Java) :

You can use the Blobstore API to store blobs in Cloud Storage instead of storing them in Blobstore. You need to set up a bucket as described in the Google Cloud Storage documentation and specify the bucket and filename in the BlobstoreService createUploadUrl, specify the bucket name in the UploadOptions parameter. In your upload handler, you need to process the returned FileInfo metadata and explicitly store the Google Cloud Storage filename needed to retrieve the blob later.

虽然没有完整的 Java 示例应用程序。

关于java - 将文件直接上传到 Google Cloud Storage for GAE 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37225000/

相关文章:

google-cloud-storage - 谷歌云运行: upload to gcs: data transfer limit?

java - 单击图像时不出现对话框 fragment

java - Jenkins 将参数传递给 testNG Java

java - 如何识别SQS-Queue不存在?

python - 自定义用户身份验证。它是如何完成的,有最佳实践吗?

java - 使用 HTTP 3XX 重定向到 Google Cloud Storage 对象?

node.js - 无法选择区域和/或区域。部署 NodeJS 托管虚拟机应用程序时

google-cloud-platform - 允许对 GCS 存储桶进行公共(public)读取访问吗?

java - RAD 不会将类文件部署到正在运行的 websphere 服务器(本地 development0

java - 使用 Google Cloud Storage 的客户端库可恢复上传