Create an application running this code:
StorageOptions.defaultInstance().service().readAllBytes(bucket, objectName)
It will work on a local environment using application default credentials, but it will throw the following error when deployed on App Engine standard (did not try on flexible):
com.google.cloud.storage.StorageException: 401
Login Required
at com.google.cloud.storage.spi.DefaultStorageRpc.translate(DefaultStorageRpc.java:98)
at com.google.cloud.storage.spi.DefaultStorageRpc.load(DefaultStorageRpc.java:362)
at com.google.cloud.storage.StorageImpl$16.call(StorageImpl.java:443)
at com.google.cloud.storage.StorageImpl$16.call(StorageImpl.java:440)
at com.google.cloud.RetryHelper.doRetry(RetryHelper.java:181)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:247)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:237)
at com.google.cloud.storage.StorageImpl.readAllBytes(StorageImpl.java:440)
The workaround is to use Storage.reader() to get a ReadChannel.
Create an application running this code:
It will work on a local environment using application default credentials, but it will throw the following error when deployed on App Engine standard (did not try on flexible):
The workaround is to use Storage.reader() to get a ReadChannel.