Google Cloud Services - Storage

This extension allows to inject a object inside your Quarkus application.

Be sure to have read the Google Cloud Services extension pack global documentation before this one, it contains general configuration and information.

Bootstrapping the project

First, we need a new project.Create a new project with the following command (replace the version placeholder with the correct one):

mvn io.quarkus:quarkus-maven-plugin:<quarkusVersion>:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=bigquery-quickstart \
cd storage-quickstart

This command generates a Maven project, importing the Google Cloud Storage extension.

If you already have your Quarkus project configured, you can add the quarkus-google-cloud-storage extension to your project by running the following command in your project base directory:

./mvnw quarkus:add-extension -Dextensions="quarkus-google-cloud-storage"

This will add the following to your pom.xml:


Preparatory steps

To test Storage you first need to create a bucket named quarkus-hello then upload a file hello.txt in it. This file will be read by the test and returned from the endpoint.

You can use gsutil:

gsutil mb gs://quarkus-hello
echo "Hello World!" > hello.txt
gsutil cp hello.txt gs://my-bucket

Some example

This is an example usage of the extension: we create a REST resource with a single endpoint that gets the hello.txt object from the quarkus-hello bucket and returns its content.

import javax.inject.Inject;


public class StorageResource {

    Storage storage;// Inject Storage

    public String storage() {
        Bucket bucket = storage.get("quarkus-hello");// Get the bucket
        Blob blob = bucket.get("hello.txt"); // Get the object
        return new String(blob.getContent()); // Return its content