I am using a Google Cloud Storage client library, specifically for Java, to download an entire bucket’s content at once using code taken from the docs. Unfortunately I get the error “FAILED_TO_START” with the message “Error requesting access token”
I have tried Google-ing the error but to no avail.
Here is my code:
public void downloadAllMovieImages() throws FileNotFoundException, IOException {
Path dir = Paths.get("src/main/resources/com/texnologia_logismikou/Cinematrix/images/");
FileInputStream creds = new FileInputStream(credentialsPath); // <--- Path to credentials.
Storage storage = StorageOptions.newBuilder()
.setProjectId(projectId)
.setCredentials(GoogleCredentials.fromStream(creds))
.build()
.getService();
List<BlobInfo> blobs = storage.list(bucketName)
.streamAll()
.map(blob -> blob.asBlobInfo())
.collect(Collectors.toList());
TransferManager transferManager = TransferManagerConfig.newBuilder()
.build()
.getService();
ParallelDownloadConfig parallelDownloadConfig = ParallelDownloadConfig.newBuilder()
.setBucketName(bucketName)
.setDownloadDirectory(dir)
.build();
List<DownloadResult> results = transferManager.downloadBlobs(blobs, parallelDownloadConfig).getDownloadResults();
for (DownloadResult result : results) {
System.out.println(
"Download of "
+ result.getInput().getName()
+ " completed with status "
+ result.getStatus() + " "
+ result.getException().getCause() + " ");
}
}
Also it is important to mention that I am using the credentials of a Service Account that has the following permissions:
- Storage Admin
- Storage Object Viewer
- Cloud Storage for Firebase Admin
- Cloud Storage for Firebase Service Agent
It is also worth noting that if I try to download a single image from the bucket, I get no errors and the image appears in the specified directory. However, in this exaxmple, the image files appear in the directory but since the download never starts Windows says that the files are corrupted. The bucket contains 3 jpg images.
What is going on with this error? Am I missing something in my code?