Hi,

I'm currently creating an android app but have got stuck trying to upload 
images to google cloud storage through cloud endpoints. Originally my idea 
was to upload the image byte array (they are 100kb max images) through the 
rest endpoint however I receive errors as the data when encoded to base64 
has some characters that JSON doesn't like (according to my error console 
anyway). My second shot was to use the BlobstoreService with code:

BlobstoreService blobstoreService = BlobstoreServiceFactory.
getBlobstoreService();
UploadOptions uploadOptions = UploadOptions.Builder.
withGoogleStorageBucketName("dcimg13");
String url = blobstoreService.createUploadUrl("/uploaded", uploadOptions);

Then once returned to the Android device, I use the following code to 
upload the image:

HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost(url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.
BROWSER_COMPATIBLE);
entity.addPart("data", new ByteArrayBody(data,"image/png","img.png"));
httppost.setEntity(entity);
String res = EntityUtils.toString( httpclient.execute(httppost).getEntity(), 
"UTF-8");

This seems to work and upload the image (Although I get a 404 error because 
the "/uploaded" page does not exist). However, I have no idea how I can 
find the key. How can I find this key?

Also, with this code I manage to retrieve the URL for the image (only after 
manually looking up the key for the image in the datastore first):
 private String getThumbUrl(BlobKey blobkey){       
 ServingUrlOptions options = ServingUrlOptions.Builder.withBlobKey(blobkey);
 try {
 return ImagesServiceFactory.getImagesService().getServingUrl(options);
 } catch(IllegalArgumentException e) {
 e.printStackTrace();
 return null;
 } catch(ImagesServiceFailureException e) {
 e.printStackTrace();
 return null;
 }
 }

However, for some reason the image at the url has kind of inverted colours 
etc. (black is blue and white is black). The images I am uploading are 
indexed png's. Could that have anything to do with it?

Cheers,
Ben

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to