Read file from cloud storage bucket

This lesson describe how to read a file from the cloud storage bucket

In this example, the function code accepts the bucketName and the sourceFilePath

As input parameters. It fetches the file as a byte array (base64 encoded in a remote call due to JSON serialization) format and returns by wrapping it inside the Result class. If there is a failure then the failed Result is returned.

Code: /lessons/Read_File_from_Cloud_Storage_Bucket

Prerequisite

In this lesson it is assumed that you have a file available in the cloud storage bucket. The file is included in the lesson’s directory. The bucket view is shown below.

Steps

  1. Create a new function called ReadFileFromCloudStorageBucket.java.

  2. Upload a file to the GCS bucket.

  3. Set passed parameters as the name of the bucket and file path.

  4. Call StorageApi.readFromBucket function with the above parameters.

  5. This API returns Result. Verify the result and display number of bytes.

  6. Return the response.

Last updated