> For the complete documentation index, see [llms.txt](https://mercure-technologies.gitbook.io/xprem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mercure-technologies.gitbook.io/xprem/storage/google-cloud-storage.md).

# Google Cloud Storage

Use Google Cloud Storage (GCS) to store and deliver update assets.

### Configure storage

Set these environment variables:

```dotenv
STORAGE_MODE=gcs
GCS_BUCKET_NAME=your-bucket-name
GOOGLE_APPLICATION_CREDENTIALS_B64=<base64-encoded service account JSON>
```

### Create service account credentials

{% stepper %}
{% step %}

#### Create a service account

In the GCP Console, go to **IAM & Admin** → **Service Accounts**.

Create a service account or select an existing one.
{% endstep %}

{% step %}

#### Grant bucket access

Go to **Cloud Storage** → **Buckets** and select your bucket.

Open **Permissions**, then select **Grant Access**. Add the service account with the **Storage Admin** role.
{% endstep %}

{% step %}

#### Create and encode a key

Go to **Service Accounts** → **Keys** → **Add Key** → **Create new key**.

Choose **JSON**, then encode the downloaded file:

```shellscript
base64 -i /path/to/service-account.json | tr -d '\n'
```

Set the result as `GOOGLE_APPLICATION_CREDENTIALS_B64`.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
The credential authenticates object operations and generates signed URLs.
{% endhint %}

### Asset delivery

When a client requests an update, xprem returns a URL for each asset.\
How that URL is produced depends on your configuration.

[**Generic CDN**](/xprem/cdn/generic-cdn.md)**:** set `CDN_BASE_URL` to serve assets through a CDN of your choice. xprem rewrites asset URLs to your CDN hostname, which caches them and reads from your bucket on a miss.

**Direct from storage:** the default once `GOOGLE_APPLICATION_CREDENTIALS_B64` is set. xprem returns pre-signed GCS URLs valid for 15 minutes, so clients download straight from your bucket while it stays private. No CDN configuration is required.

**Through the server:** xprem fetches each object from GCS and streams it back itself. This happens when no `GOOGLE_APPLICATION_CREDENTIALS_B64` is configured, or when the client sends the `prevent-cdn-redirection: true` header. Every asset byte then transits through your server, so size it accordingly.

### Required permissions

Grant the service account the **Storage Admin** role on the bucket. It provides:

* `storage.objects.get` — Read objects.
* `storage.objects.list` — List branches, runtime versions, and updates.
* `storage.objects.create` — Upload updates.
* `storage.objects.delete` — Remove updates.
* Signed URL generation — Deliver assets directly from GCS.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mercure-technologies.gitbook.io/xprem/storage/google-cloud-storage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
