NashTech Insights

Spring Cloud GCP – Cloud Storage

Agnibhas Chattopadhyay
Agnibhas Chattopadhyay
Table of Contents

Spring Cloud GCP

The Spring framework! It’s not just popular, it’s the ultimate go-to framework for developers all around the world. Since its inception, Spring has been revolutionizing the Java landscape with its versatility and reliability. And now, enter Spring Cloud GCP, the result of an extraordinary collaboration between Spring and Google Cloud Platform.

This project seamlessly integrates the power of Spring with the cutting-edge features of the Google Cloud Platform. Spring Cloud GCP empowers developers to harness the immense potential of Google Cloud Platform, unleashing a whole new realm of possibilities for building robust and scalable applications.

Spring Cloud GCP comprises of multiple libraries that enable seamless integration between Springboot applications and various GCP services. With Spring Cloud GCP, developers gain direct access to a wide range of services offered by the Google Cloud Platform. Note that while Spring Cloud GCP offers support for a vast majority of services, not all services are currently included. The project continues to evolve, expanding the list of supported services and enhancing the overall functionality.

You can find comprehensive information about Spring Cloud GCP on its official website, accessible through this link. This website offers precise details regarding the features and services provided by Spring Cloud GCP, along with relevant documentation to assist you in getting started. While the page covers a wide array of services, our focus for this article will be on Google Cloud Storage, one of the services offered by Spring Cloud GCP.

Google Cloud Storage

Google Cloud Storage is a highly scalable, durable, and cost-effective object storage service that Google Cloud Platform (GCP) offers. It facilitates the storage and management of substantial volumes of unstructured data. This solution provides noteworthy performance and reliability and can effectively meet the needs of various applications, including data backups and content delivery for websites and applications. Google Cloud Storage’s fundamental building block is the object, which consists of the actual content, metadata, and a unique identifier. Users can utilize different storage classes, namely Standard, Nearline, Coldline, and Archive, to fulfill specific access speed and cost requirements.

Google Cloud Storage allows users to access and manipulate data through a user-friendly web-based console, RESTful APIs for programmatic integration, command-line tools, and software development kits (SDKs) for multiple programming languages. Google Cloud IAM manages fine-grained access controls and permissions, enabling granular control over bucket and object-level access permissions. To ensure high durability and availability, Google Cloud Storage distributes data across multiple geographic regions, reducing risks associated with hardware failures and other contingencies. Additionally, the service seamlessly scales to accommodate evolving storage needs, automating expansion tasks without requiring manual intervention.


There are multiple ways to access and use Google Cloud Storage:

  • Console: The Google Cloud console provides a visual interface for you to manage your data in a browser.
  • Google Cloud CLI: The gcloud CLI allows you to interact with Cloud Storage through a terminal using gcloud storage commands.
  • Client libraries: The Cloud Storage client libraries allow you to manage your data using multiple languages.
  • REST APIs: Manage your data using the JSON or XML API.
  • TerraformTerraform is an infrastructure-as-code (IaC) tool that you can use to provision the infrastructure for Cloud Storage.
  • Cloud Storage FUSECloud Storage FUSE allows you to mount Cloud Storage buckets to your local file system. This enables your applications to read from a bucket or write to a bucket by using standard file system semantics.

Enough theory let’s try out an implementation and see how can we access GCS using Spring Cloud GCP. For this we will setup our GCP account and use the credentials to access GCS using REST APIs from our Springboot app.

Set up your Google Cloud Project

Spring Cloud GCP Create Project
Set up Google Cloud SDK and Authentication

  • Install the Google Cloud SDK:
  • Create a Spring Boot Project You can create a Spring Boot project using a tool like Spring Initializr (, or use your preferred IDE to create a new Spring Boot project.
  • Configure authentication:
    • After you have installed Google Cloud SDK open up the terminal in your IDE and run
    • gcloud auth login
    • Now a browser window will open up asking for permission to access your GCP account. Allow it and go back to your Terminal and run:
    • gcloud config set project PROJECT_ID (replace PROJECT_ID with your Google Cloud Project ID).
  • Now we can access all GCP resources from our local machine.

Springboot Application

Add the required dependencies:

For Maven:



For Gradle:

implementation platform('')

implementation ''
Create a Service to interact with GCS:

public class GcsService {

    private String bucketName = your-gcs-bucket-name;

    private final Storage storage;

    public GcsService() { = StorageOptions.getDefaultInstance().getService();

    public void writeDataToGcs(String filename, String data) throws IOException {
        Bucket bucket = storage.get(bucketName);
        bucket.create(filename, data.getBytes(StandardCharsets.UTF_8));

    public String readDataFromGcs(String filename) throws IOException {
        Bucket bucket = storage.get(bucketName);
        return new String(bucket.get(filename).getContent(), StandardCharsets.UTF_8);
Create a REST Controller to expose GCS operations:

public class GcsController {

    private GcsService gcsService;

    public void writeData(@RequestParam String filename, @RequestParam String data) throws IOException {
        gcsService.writeDataToGcs(filename, data);

    public String readData(@RequestParam String filename) throws IOException {
        return gcsService.readDataFromGcs(filename);
Run the application and test:

Please proceed with running your Spring Boot application. Once successfully executed, you will gain access to the REST endpoints /gcs/write and /gcs/read. These endpoints will enable you to facilitate the writing and reading of data to and from Google Cloud Storage.

NOTE: When you are done with all the tasks please do not forget to delete the Cloud Storage buckets/objects to avoid additional charges.


In conclusion, our Springboot application provides a seamless integration with Google Cloud Storage, enabling efficient data storage and retrieval. Stay tuned for more insightful articles on cutting-edge technologies at Nashtech Blogs, where we continue to explore and share the latest innovations in the tech industry.


All the contents in this blog are referred from Google Cloud Platform and Spring Cloud GCP documentation and guides.

Agnibhas Chattopadhyay

Agnibhas Chattopadhyay

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

%d bloggers like this: