如何使用GAE / Cloud Endpoints API方法将图像上传到Google云端存储

时间:2022-02-16 20:18:19

Does anyone have an example of a GAE/Cloud Endpoints API method (in Java) that can take in an image from an Android app and upload it to Google Cloud Storage?

有没有人有一个GAE / Cloud Endpoints API方法(用Java)的例子,它可以从Android应用程序中获取图像并将其上传到Google云端存储?

I cannot seem to find any samples on how to do this but it is possible from what I understand.

我似乎无法找到关于如何做到这一点的任何样本,但根据我的理解,这是可能的。

EDIT: The tutorial here shows how to add a dependency to google app engine in eclipse and upload/download an image to Google Cloud Storage. Is it possible to do this with Cloud Endpoints somehow..? After all, they are both Google App Engine.

编辑:此处的教程显示如何在eclipse中向谷歌应用引擎添加依赖项,并将图像上传/下载到谷歌云存储。是否有可能以某种方式使用Cloud Endpoints执行此操作..?毕竟,它们都是Google App Engine。

I want to offload as much of the upload/download code into my Cloud Endpoints API method(s), rather than coding everything inside of Android. This would allow me to reuse my Cloud Endpoints API on other clients.

我想将尽可能多的上传/下载代码卸载到我的Cloud Endpoints API方法中,而不是编写Android内部的所有代码。这将允许我在其他客户端上重用我的Cloud Endpoints API。

More info I found: https://developers.google.com/api-client-library/java/apis/storage/v1#sample

更多信息我发现:https://developers.google.com/api-client-library/java/apis/storage/v1#sample

Looks like this is the gradle dependency for the cloud endpoints backend?:

看起来这是云端点后端的gradle依赖?:

dependencies {
    compile 'com.google.apis:google-api-services-storage:v1-rev66-1.21.0'
}

EDIT:

编辑:

You should use this dependency inside cloud endpoints:

您应该在云端点中使用此依赖关系:

compile 'com.google.appengine.tools:appengine-gcs-client:0.5'

3 个解决方案

#1


2  

You can upload file to Google Storage using Json Api

您可以使用Json Api将文件上传到Google Storage

You may or may not want to store file metadata to datastore thru Endpoints.

您可能希望也可能不希望通过端点将文件元数据存储到数据存储区。

You may or may not want to authenticate your users thru Endpoints before give them possibility to store files to Storage.

您可能希望也可能不希望通过端点对用户进行身份验证,然后才能将文件存储到存储。

What I want to say is that Storage / Endpoints / Datastore are three different things and you don't required to use them all together.

我想说的是存储/端点/数据存储是三个不同的东西,你不需要一起使用它们。

Useful link: https://github.com/pliablematter/simple-cloud-storage

有用的链接:https://github.com/pliablematter/simple-cloud-storage

#2


1  

You cannot directly upload (large) files to an Endpoints API method but instead need to receive them using the blobstore (or GCS) (https://cloud.google.com/appengine/docs/python/blobstore/ ). This requires the following:

您无法直接将(大)文件上载到Endpoints API方法,而是需要使用blobstore(或GCS)(https://cloud.google.com/appengine/docs/python/blobstore/)接收它们。这需要以下内容:

  • Setup on your server a blobstore upload handler (which is just a regular webapp2 handler).
  • 在服务器上设置blobstore上传处理程序(这只是一个常规的webapp2处理程序)。
  • Expose an Endpoints method that calls blobstore.create_upload_url(), and then returns the upload URL to your App.
  • 公开调用blobstore.create_upload_url()的Endpoints方法,然后将上传URL返回到您的App。
  • Within the App, upload the picture to that upload URL; the file will then be accessible within your upload handler, where you can move it to GCS, Datastore or somewhere else.
  • 在应用程序中,将图片上传到该上传URL;然后,您可以在上传处理程序中访问该文件,您可以将其移动到GCS,数据存储区或其他位置。

#3


1  

Solution : https://github.com/thorrism/GoogleCloudExample

解决方案:https://github.com/thorrism/GoogleCloudExample

Enable Google Cloud Storage : => https://console.developers.google.com/apis

启用Google云端存储:=> https://console.developers.google.com/apis

Generate and download a key P12 : => https://console.developers.google.com/iam-admin/iam Create a folder named "assets" and place there your key : => app/src/main/assets/"yourKey.P12"

生成并下载密钥P12:=> https://console.developers.google.com/iam-admin/iam创建一个名为“assets”的文件夹并放置密钥:=> app / src / main / assets /“ yourKey.P12"

For everyone can access your uploaded file reading do not forget to add the permissions on your Bucket

对于每个人都可以访问您上传的文件阅读不要忘记在您的Bucket上添加权限

#1


2  

You can upload file to Google Storage using Json Api

您可以使用Json Api将文件上传到Google Storage

You may or may not want to store file metadata to datastore thru Endpoints.

您可能希望也可能不希望通过端点将文件元数据存储到数据存储区。

You may or may not want to authenticate your users thru Endpoints before give them possibility to store files to Storage.

您可能希望也可能不希望通过端点对用户进行身份验证,然后才能将文件存储到存储。

What I want to say is that Storage / Endpoints / Datastore are three different things and you don't required to use them all together.

我想说的是存储/端点/数据存储是三个不同的东西,你不需要一起使用它们。

Useful link: https://github.com/pliablematter/simple-cloud-storage

有用的链接:https://github.com/pliablematter/simple-cloud-storage

#2


1  

You cannot directly upload (large) files to an Endpoints API method but instead need to receive them using the blobstore (or GCS) (https://cloud.google.com/appengine/docs/python/blobstore/ ). This requires the following:

您无法直接将(大)文件上载到Endpoints API方法,而是需要使用blobstore(或GCS)(https://cloud.google.com/appengine/docs/python/blobstore/)接收它们。这需要以下内容:

  • Setup on your server a blobstore upload handler (which is just a regular webapp2 handler).
  • 在服务器上设置blobstore上传处理程序(这只是一个常规的webapp2处理程序)。
  • Expose an Endpoints method that calls blobstore.create_upload_url(), and then returns the upload URL to your App.
  • 公开调用blobstore.create_upload_url()的Endpoints方法,然后将上传URL返回到您的App。
  • Within the App, upload the picture to that upload URL; the file will then be accessible within your upload handler, where you can move it to GCS, Datastore or somewhere else.
  • 在应用程序中,将图片上传到该上传URL;然后,您可以在上传处理程序中访问该文件,您可以将其移动到GCS,数据存储区或其他位置。

#3


1  

Solution : https://github.com/thorrism/GoogleCloudExample

解决方案:https://github.com/thorrism/GoogleCloudExample

Enable Google Cloud Storage : => https://console.developers.google.com/apis

启用Google云端存储:=> https://console.developers.google.com/apis

Generate and download a key P12 : => https://console.developers.google.com/iam-admin/iam Create a folder named "assets" and place there your key : => app/src/main/assets/"yourKey.P12"

生成并下载密钥P12:=> https://console.developers.google.com/iam-admin/iam创建一个名为“assets”的文件夹并放置密钥:=> app / src / main / assets /“ yourKey.P12"

For everyone can access your uploaded file reading do not forget to add the permissions on your Bucket

对于每个人都可以访问您上传的文件阅读不要忘记在您的Bucket上添加权限