编程语言
首页 > 编程语言> > java-将文件直接上传到Google Cloud Storage for GAE应用

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

作者:互联网

我正在考虑从Blobstore切换到Google Cloud Storage,以进行项目中的图片上传等操作(因为Google称Blobstore为“已取代”).

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

是否可以通过Google Cloud Storage(GCS)实施类似的工作流程?

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

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

是否没有一种方法可以简单地为GCS中的资源生成URL(AFAIK AWS S3支持此URL)并从那里提供资源?

解决方法:

您可以继续使用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 07001 documentation and specify the bucket
and filename in the 07002
gs_bucket_name parameter. In your upload handler, you need to process the returned 07003 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 07005 documentation and specify the bucket
and filename in the BlobstoreService 07006, specify
the bucket name in the UploadOptions parameter. In your upload
handler, you need to process the returned 07007 metadata and
explicitly store the Google Cloud Storage filename needed to retrieve
the blob later.

尚无Java的完整示例应用程序.

标签:google-cloud-storage,google-app-engine,java
来源: https://codeday.me/bug/20191027/1941345.html