2
votes

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?

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.

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.

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

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

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

3 Answers

2
votes

You can upload file to Google Storage using Json Api

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

1
votes

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:

  • Setup on your server a blobstore upload handler (which is just a regular webapp2 handler).
  • Expose an Endpoints method that calls blobstore.create_upload_url(), and then returns the upload URL to your 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.
0
votes

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

Enable Google Cloud Storage : => 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"

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