# gatsby-source-gcs-image

> GatsbyJS plugin to source images from Google Cloud Storage

Latest version **2.0.0** (published 2026-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-source-gcs-image
pnpm add gatsby-source-gcs-image
yarn add gatsby-source-gcs-image
bun add gatsby-source-gcs-image
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-08-11 |
| First published | 2023-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 20.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Parker Holladay |
| Maintainers | parker-holladay |
| Keywords | cloud storage, gatsby, gatsby-plugin, gatsby-source, gcs |

## Links

- npm: https://www.npmjs.com/package/gatsby-source-gcs-image
- npm.io page: https://npm.io/package/gatsby-source-gcs-image

## Dependencies (2)

- [@google-cloud/storage](https://npm.io/package/@google-cloud/storage.md) 6.12.0
- [gatsby-source-filesystem](https://npm.io/package/gatsby-source-filesystem.md) 5.11.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-08-11
- 1.1.2 — 2026-08-11
- 1.1.1 — 2023-07-22
- 1.1.0 — 2023-03-13
- 1.0.1 — 2023-03-09
- 1.0.0 — 2023-03-09

## README

<p align="center">
  <a href="https://github.com/parkerholladay/gatsby-source-gcs-image">
    <img src="https://github.com/parkerholladay/gatsby-source-gcs-image/raw/master/assets/logo.svg" width="100" />
  </a>
</p>
<h1 align="center">
  gatsby-source-gcs-image
</h1>

[![build status](https://img.shields.io/github/actions/workflow/status/parkerholladay/gatsby-source-gcs-image/build.yaml?branch=master&logo=github&style=for-the-badge)](https://github.com/parkerholladay/gatsby-source-gcs-image/actions)
[![npm](https://img.shields.io/npm/v/gatsby-source-gcs-image?logo=npm&style=for-the-badge)](https://www.npmjs.com/package/gatsby-source-gcs-image)
![license](https://img.shields.io/npm/l/gatsby-source-gcs-image?style=for-the-badge)
![test coverage](https://img.shields.io/nycrc/parkerholladay/gatsby-source-gcs-image?label=functions&preferredThreshold=functions&style=for-the-badge)
![test coverage](https://img.shields.io/nycrc/parkerholladay/gatsby-source-gcs-image?label=lines&preferredThreshold=lines&style=for-the-badge)

## What Is This?

`gatsby-source-gcs-image` is a [GatsbyJS](https:///gatsbyjs.com) _source_ plugin that converts images from Google Cloud Storage into GatsbyJS `File` nodes--much like how [this plugin](https://gatsbyjs.com/plugins/gatsby-source-s3-image) works with AWS S3. See [here](https://github.com/jessestuart/gatsby-source-s3-image#but-i-can-just-query-s3-manually-client-side) for more.

The created GatsbyJS `File` nodes can then be manipulated with image processors like [sharp](https://gatsbyjs.com/plugins/gatsby-plugin-sharp).

## Usage

### Install

```bash
npm install --save-dev gatsby-source-gcs-image
```

_or_

```bash
yarn add -D gatsby-source-gcs-image
```

### Configure

At a minimum GCP creds must be provided with either `credsJson` or `pathToCreds`. Some example configurations are:

```javascript
// gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-gcs-image',
      options: {
        bucketName: 'my-gcs-bucket.appspot.com',
        bucketPath: '/path/to/images',
        concurrency: 10,
        pathToCreds: `${__dirname}/.gcp-creds.json`,
        projectId: 'my-gcp-project',
      },
    },
    // ...image transform plugins
  ],
}
```

_or_

```javascript
// gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-gcs-image',
      options: {
        credsJson: process.env.ENV_VAR_WITH_CREDS,
      },
    },
    // ...image transform plugins
  ],
}
```

#### Fields

| name        | type   | default | required | description |
| ----------- | ------ | :-----: | :------: | ----------- |
| bucketName  | string |         | *        | GCS bucket _(may exist in creds)_ |
| bucketPath  | string |         |          | prefix to source images from |
| concurrency | number | 10      |          | how many objects to source at once |
| credsJson   | string |         | *        | JSON string with creds _(optional if `pathToCreds` is provided)_ |
| pathToCreds | string |         | *        | JSON file with creds _(optional if `credsJson` is provided)_ |
| projectId   | string |         | *        | GCP project id _(may exist in creds)_ |

#### Caching

Images are cached on their GCS [object generation](https://cloud.google.com/storage/docs/metadata#generation-number),
so an object is only re-downloaded when its contents actually change. Unchanged objects are skipped
entirely on subsequent builds — no signing, no download.

Signed urls are used only as a build-time transport and never reach the built site, which embeds
static, transformed copies of every image. Their lifetime is therefore an internal detail rather
than a configurable option.

### Upgrading from 1.x

`2.0.0` replaces clock-based caching with generation-based caching. Two breaking changes:

- the **`expires` option** has been removed — url lifetime is no longer configurable
- the **`expiresAt` field** has been removed from the `GcsImage` node

`gcsPath` and `generation` are now exposed on the node. Nothing changes for queries that use `name`
and `childImageSharp`.

Previously, an expiring url forced a full re-download of every object and rotated every underlying
`File` node id once per expiry window. Any `expires` value below 10 minutes silently disabled caching
altogether.

### Query Data

```javascript
export const pageQuery = graphql`
  {
    allGcsImage {
      edges {
        node {
          name
          childImageSharp {
            gatsbyImageData(layout: CONSTRAINED, width: 800)
          }
        }
      }
    }
  }
`
```

---
_Source: https://npm.io/package/gatsby-source-gcs-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
