1

I'm really needing your help/suggestion/clue/etc. I'm developing an application for Android and iOS which will allow the user to upload pictures and videos.

What I'm trying to do:

1 - Android/iOS send picture/video to my Google Cloud Endpoint;

2 - Google Cloud Endpoint upload the image/video to Google Cloud Storage; (Works)

3 - Google Cloud Endpoint retrieve the servingURL from Google Cloud Storage and send back to Android/iOS; (Works)

4 - Android/iOS stream the picture/video by its URL. (Works)

So the problem is just the first step, send the image/video to Google Cloud Endpoint.

I'm reading a lot, searching, researching and didn't figured out how to do it.

Please, ANY suggestion will be appreciate. I'm open to new ideas about the way to implement this feature as well. Thank you guys!

.

- - - - - - - - - - - - - - - - - - - - -- - - - - - - - UPDATE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

.

After research a bit more I noticed the better way to do it would be uploading straight from Android/iOS. I figured out how to do it but now I got stuck about how to implement the servlet to get called automatically after the client upload the file using the urlUpload generated by my endpoint.

So far I did:

1 - Client request my Google Endpoint to retrieve URL for upload;

2 - Google Endpoint generates '/upload' url using with this code:

BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
UploadOptions uploadOptions = UploadOptions.Builder.withGoogleStorageBucketName(ConstUtil.storage.BUCKET_NAME);

String uploadUrl = blobstoreService.createUploadUrl("/upload", uploadOptions);

response.setSimpleString(uploadUrl);
response.setCode(MWCode.SUCCESS.getCode());
response.setMessage(MWCode.SUCCESS.getMessage());

return response;

3 - Client (Android/iOS) receive this url and upload the file (I didn't implement it yet but I saw many clean example and looks very easy to understand)

4 - Blobstore service fire Google Endpoint as callback sending keys of the uploaded object

5 - I use Blob keys to retrieve servingURL to serve the files with clients (Android/iOS) (already implemented)

I have no idea about how to implement the step 4 once all tutorials and examples I see are not using Google Cloud Endpoints. Please, does anyone can give me the path/link/code or clue of how I could implement it?

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
John Santos
  • 485
  • 4
  • 18

2 Answers2

2

If you're using the Endpoints frameworks, this is pretty hard to do. For single images, you can base64 encode them, but that's not very efficient. It probably works better for your client to interact directly with GCS and use a signed URL for upload.

saiyr
  • 2,575
  • 1
  • 11
  • 13
  • Yea, after research a bit more I noticed the better way to do it would be uploading straight from Android/iOS. I figured out how to do it but now I got stuck about how to implement the servlet (being an endpoint) to get called automatically after the client upload the file using the urlUpload generated by my endpoint. Going to update the question. – John Santos Dec 01 '16 at 12:13
2

As Saiyr suggested, you should upload directly to the Cloud Storage from the Android application (without going through Endpoints). See Uploading image from Android to GCS and upload image to google cloud storage with an application android.

Since you know the bucket and file name, the URL of the uploaded file is easily deductible, see the following documentation to decide which URL to use (depending on whether the user shall be authenticated or not, see Section "A user is granted read access to an object") https://cloud.google.com/storage/docs/cloud-console#_accessing

Community
  • 1
  • 1
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
  • Yea I got the url for download and the upload from client is working fine. Now I don't know how to get the uploaded file on my endpoint (servlet). I mean, the user uploaded the video/picture, now, how can I get this uploaded file on my server side so I can get the url to serve this file? – John Santos Dec 04 '16 at 21:34
  • If I understand well, you know the bucket and file names of the file you have uploaded to the Cloud Storage. If this is the case, it is easy to get the URL to serve the file: see the doc https://cloud.google.com/storage/docs/cloud-console#_accessing. If the file is to be shared publicly, the URL is like: https://storage.googleapis.com//. This does not require to authenticate with Google. On the other hand, if the file is protected by user name/password, you should use https://console.cloud.google.com/storage/browser//. Look the doc, it is crystal clear!! – Renaud Tarnec Dec 05 '16 at 20:53
  • Sorry about my english, it's crap. The point is, it's not where I'm stuck. I'm trying to implement this very simple example: https://medium.com/google-cloud/uploading-to-google-cloud-storage-from-ios-app-e9f4097b516#.fxu3djvzs but I couldn't figure out how the method "doPost" is called after client (Android/iOS) upload the media. – John Santos Dec 06 '16 at 08:40