0

I have an android app that wants to include image sending in the instant messaging client. I'm terribly confused on the way to do this using the blobstore or google cloud storage. Can someone please outline the steps to achieve this from the backend perspective? My goal is to end up using getServingUrl and have an external url for the app to hit and get the image. I'm using java and google cloud endpoints.

So far, I have: 1. createUploadUrl 2.user blogstore service .getUploads() to get BlobKeys 3.find my specific blob key (by ID, blobs.get(ID) i think) 4. magic 5. figure out how to use .getServingUrl(options) on a specific blob 6. backend works.

Please include code or psuedocode in your response, as I've been working on this for days and am beyond exhausted. I could really use someone to ELI5.

Japes
  • 255
  • 2
  • 16

1 Answers1

1

I think the confusing thing is trying to use it with cloud endpoints, which is not what you are supposed to do. Use a pure Servlets (or an abstraction over Servlet which gets you access to HttpServletRequest). Get the BlobKey using BlobstoreService.getUpload(HttpServletRequest):

public void doGet(HttpServletRequest request, HttpServletResponse response) {
  BlobKey blobKey = blobstoreService.getUploads(request).get("file").get(0); // assume the form parameter was "file" and only one file was uploaded
}

and use ImagesService.getServingUrl (set the BlobKey in the Options builder) to get the URL.

String url = imagesService.getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey));

You may want to serialize the BlobKey (with getKeyString) to the datastore for future access.

Gabriel
  • 862
  • 6
  • 18
  • I thought maybe this was the case. ive never used java servlets, and I didnt want to because all the examples used web based forms, and not android. So I don't really understand how to sue them with android. Can you elaborate on that? – Japes May 26 '15 at 08:27
  • This should help: http://stackoverflow.com/questions/2017414/post-multipart-request-with-android-sdk – Gabriel May 26 '15 at 08:30
  • still a little confused but it is near the end of day and I'm bushwacked. I will take a look again tomorrow. thanks – Japes May 26 '15 at 08:41