Google Cloud Storage
Stores files in Google Cloud Storage. For interface details, see WorkspaceFilesystem Interface.
InstallationInstallation的直接链接
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/gcs
pnpm add @mastra/gcs
yarn add @mastra/gcs
bun add @mastra/gcs
UsageUsage的直接链接
Add a GCSFilesystem to a workspace and assign it to an agent:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { GCSFilesystem } from '@mastra/gcs'
const workspace = new Workspace({
filesystem: new GCSFilesystem({
bucket: 'my-gcs-bucket',
projectId: 'my-project-id',
credentials: JSON.parse(process.env.GCS_SERVICE_ACCOUNT_KEY),
}),
})
const agent = new Agent({
id: 'file-agent',
name: 'file-agent',
model: 'anthropic/claude-opus-4-7',
workspace,
})
Using Application Default CredentialsUsing Application Default Credentials的直接链接
If running on Google Cloud or with gcloud CLI configured, you can omit credentials:
import { GCSFilesystem } from '@mastra/gcs'
const filesystem = new GCSFilesystem({
bucket: 'my-gcs-bucket',
// Uses Application Default Credentials automatically
})
Application Default Credentials (ADC) automatically discovers credentials in this order:
GOOGLE_APPLICATION_CREDENTIALSenvironment variable (path to a service account key file)- Default service account when running on GCP (Compute Engine, Cloud Run, GKE, etc.)
- User credentials from
gcloud auth application-default login(for local development)
Using a Key File PathUsing a Key File Path的直接链接
You can also pass a path to a service account key file:
import { GCSFilesystem } from '@mastra/gcs'
const filesystem = new GCSFilesystem({
bucket: 'my-gcs-bucket',
projectId: 'my-project-id',
credentials: '/path/to/service-account-key.json',
})
Constructor parametersConstructor parameters的直接链接
bucket:
projectId?:
credentials?:
prefix?:
id?:
displayName?:
icon?:
description?:
readOnly?:
endpoint?:
PropertiesProperties的直接链接
id:
name:
provider:
bucket:
readOnly:
MethodsMethods的直接链接
GCSFilesystem implements the WorkspaceFilesystem interface, providing all standard filesystem methods:
readFile(path, options?)- Read file contentswriteFile(path, content, options?)- Write content to a fileappendFile(path, content)- Append content to a filedeleteFile(path, options?)- Delete a filecopyFile(src, dest, options?)- Copy a filemoveFile(src, dest, options?)- Move or rename a filemkdir(path, options?)- Create a directoryrmdir(path, options?)- Remove a directoryreaddir(path, options?)- List directory contentsexists(path)- Check if a path existsstat(path)- Get file or directory metadata
init()init的直接链接
Initialize the filesystem. Verifies bucket access and credentials.
await filesystem.init()
getInfo()getinfo的直接链接
Returns metadata about this filesystem instance.
const info = filesystem.getInfo()
// { id: '...', name: 'GCSFilesystem', provider: 'gcs', status: 'ready' }
getMountConfig()getmountconfig的直接链接
Returns the mount configuration for sandboxes that support mounting this filesystem type.
const config = filesystem.getMountConfig()
// { type: 'gcs', bucket: 'my-bucket', ... }
Mounting in E2B sandboxesMounting in E2B sandboxes的直接链接
GCSFilesystem can be mounted into E2B sandboxes, making the bucket accessible as a local directory:
import { Workspace } from '@mastra/core/workspace'
import { GCSFilesystem } from '@mastra/gcs'
import { E2BSandbox } from '@mastra/e2b'
const workspace = new Workspace({
mounts: {
'/data': new GCSFilesystem({
bucket: 'my-gcs-bucket',
projectId: 'my-project-id',
credentials: JSON.parse(process.env.GCS_SERVICE_ACCOUNT_KEY),
}),
},
sandbox: new E2BSandbox({ id: 'dev-sandbox' }),
})
See E2BSandbox reference for more details on mounting.