A memo when retrieving the file contents on GCS using the Cloud Storage Client Library. In the example below, there was only an example of creating a bucket, and there was no example of reading, so I created it while looking at the API manual. https://cloud.google.com/storage/docs/reference/libraries
The following is an example of reading AWS credential information placed on GCS.
//Creation of Storage object
Storage storage = StorageOptions.getDefaultInstance().getService();
//Set Bucket name
String bucketName = "{BUKET name}";
//Set object name
String blobName = "{file name}";
//Get BlobId based on Bucket name and object name
BlobId blobId = BlobId.of(bucketName, blobName);
//Create a Blob object
Blob blob = storage.get(blobId);
//Get the contents of a Blob object
byte[] content = blob.getContent(BlobSourceOption.generationMatch());
//Since it is described in CSV format, split it and store it in each variable
String credential[] = new String(content, "UTF-8").split(",", 0);
aws_key = credential[0];
aws_secret_key = credential[1];
Recommended Posts