androidiosgoogle-cloud-platformgoogle-cloud-storagegoogle-cloud-endpoints

Send Images/Videos from Android/iOS to Google Cloud Endpoints


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?


Solution

  • 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