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外部鏈接 –