将文件直接上传到 Google Cloud Storage for GAE 应用程序
Uploading files directly to Google Cloud Storage for GAE app
我正在考虑从 Blobstore 切换到 Google Cloud Storage,以便在项目中上传图片(因为 Google 调用 Blobstore "superseded")。
在 Blobstore 中,多部分表单将直接提交(上传)到 Blobstore,然后 Blobstore 将重写请求并重定向到 GAE 应用程序以处理 BlobKey
(s)。这意味着 GAE 应用程序的负载非常小。
有没有办法通过 Google 云存储 (GCS) 实现类似的工作流程?
Reading and Writing to Google Cloud Storage 处给出的示例涉及处理上传、读取数据并将其保存在 GCS 中的 GAE 代码。
类似地为(例如)上传的图像文件提供服务:似乎必须在一个人的 GAE 代码中实现处理程序才能从 GCS 和 return 图像数据中读取。
有没有一种方法可以简单地为 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 没有完整的示例应用程序。
Google Cloud Storage 支持生成 URL 用于上传或读取。
有关详细信息,请参阅:https://cloud.google.com/storage/docs/access-control/create-signed-urls-program
gcloud-java-storage 库可以帮助创建这样的 signed URL.
我正在考虑从 Blobstore 切换到 Google Cloud Storage,以便在项目中上传图片(因为 Google 调用 Blobstore "superseded")。
在 Blobstore 中,多部分表单将直接提交(上传)到 Blobstore,然后 Blobstore 将重写请求并重定向到 GAE 应用程序以处理 BlobKey
(s)。这意味着 GAE 应用程序的负载非常小。
有没有办法通过 Google 云存储 (GCS) 实现类似的工作流程?
Reading and Writing to Google Cloud Storage 处给出的示例涉及处理上传、读取数据并将其保存在 GCS 中的 GAE 代码。
类似地为(例如)上传的图像文件提供服务:似乎必须在一个人的 GAE 代码中实现处理程序才能从 GCS 和 return 图像数据中读取。
有没有一种方法可以简单地为 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 没有完整的示例应用程序。
Google Cloud Storage 支持生成 URL 用于上传或读取。 有关详细信息,请参阅:https://cloud.google.com/storage/docs/access-control/create-signed-urls-program
gcloud-java-storage 库可以帮助创建这样的 signed URL.