Hello group. I have the same issue. So, Can I upload a file to GCS directly from Google Endpoints? Thanks so much.
PS: I have posted this http://stackoverflow.com/questions/27160672/can-i-upload-a-file-to-gcs-from-google-endpoints On Saturday, February 1, 2014 7:56:10 AM UTC-6, Atakan Sergio wrote: > > Hi Ben, > Did you get your "BlobstoreService" option working? If you manage to make > it work, can you please share your code? > Thank you in advance, > Atakan > > On Wednesday, November 13, 2013 9:28:57 AM UTC-5, Ben Evans wrote: >> >> 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/d/optout.
