Get image from Google Cloud Storage in App Engine -


i trying image in app engine backend , every time try get following error

com.google.api.client.googleapis.json.googlejsonresponseexception: 503 service unavailable  {    "code": 503,    "errors": [      {        "domain": "global",        "message": "java.io.ioexception: application default credentials not available. available if running in google compute engine. otherwise, environment variable google_application_credentials must defined pointing file defining credentials. see https://developers.google.com/accounts/docs/application-default-credentials more information.",        "reason": "backenderror"      }    ],    "message": "java.io.ioexception: application default credentials not available. available if running in google compute engine. otherwise, environment variable google_application_credentials must defined pointing file defining credentials. see https://developers.google.com/accounts/docs/application-default-credentials more information."  } 

now understanding when making request app engine backend application default credentials sufficient enough it.

the application default credentials provide simple way authorization credentials use in calling google apis.

they best suited cases when call needs have same identity , authorization level application independent of user. recommended approach authorize calls google cloud apis, particularly when you're building application deployed google app engine or google compute engine virtual machines.

taken here

this how trying image using java api

httptransport httptransport = googlenethttptransport.newtrustedtransport(); googlecredential credential = googlecredential.getapplicationdefault();  if(credential.createscopedrequired()){    credential = credential.createscoped(storagescopes.all()); }  storage.builder storagebuilder = new storage.builder(httptransport,new jacksonfactory(),credential); storage storage = storagebuilder.build();  storage.objects.get getobject = storage.objects().get("mybucket", name);  bytearrayoutputstream out = new bytearrayoutputstream();             getobject.getmediahttpdownloader().setdirectdownloadenabled(false); getobject.executemediaanddownloadto(out);  byte[] oldimagedata = out.tobytearray(); out.close();  imagesservice imagesservice = imagesservicefactory.getimagesservice();  image oldimage = imagesservicefactory.makeimage(oldimagedata); transform resize = imagesservicefactory.makeresize(width, height);  return imagesservice.applytransform(resize, oldimage); 

am using credentials wrong or can not use application default credentials?

if want access google cloud storage data app engine. should using google cloud storage client library

github project


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -