[GO] Read files on GCS using Cloud Storage Client Library

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

Read files on GCS using Cloud Storage Client Library
[Google Cloud Platform] Use Google Cloud API using API Client Library
Using Cloud Storage from Python3 (Introduction)
Read, change, and write Excel files on GCP App Engine Storage
Save files using EC2 storage without using S3
Install python library on Lambda using [/ tmp]
Implement OAuth without using client library (Java)
Read FeliCa using Pasori (RC-380S) on Mac
SELECT data using client library in BigQuery