1
我想在我的App Engine
后端,每次得到的图像我设法得到它,我得到以下错误从谷歌云存储获取的图像在App Engine中
com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service Unavailable
{
"code": 503,
"errors": [
{
"domain": "global",
"message": "java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.",
"reason": "backendError"
}
],
"message": "java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information."
}
现在是我的理解是,当从App Engine后端请求Application Default Credentials
已足够。
应用程序默认凭证提供了一种简单的方式来获取 授权凭证以用于调用Google API。
它们最适用于呼叫需要具有相同的 身份和授权级别的独立于用户的 应用程序。这是推荐的方法,用于授权拨打 Google Cloud API,特别是在您构建部署到Google App Engine或Google Compute Engine虚拟 机器的应用程序 时。
从here
采取这是我正在尝试使用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);
我只是使用证书错误得到的图像或可我不使用应用程序的默认凭据?
据我了解它的工作原理,如果你使用的是内部链接'GS://'VS外部链接 –