FilesSDKFilesystem
Stores files in any storage backend supported by FilesSDK — a unified abstraction over S3, Cloudflare R2, Google Cloud Storage, Azure Blob, Vercel Blob, MinIO, the local filesystem, and more.
For interface details, see WorkspaceFilesystem Interface.
Use FilesSDKFilesystem when you want a single adapter that can target multiple storage backends with the same code. Swap the underlying driver without changing the workspace setup. If you only target one backend and want first-class options for that backend, prefer the dedicated provider (for example S3Filesystem or GCSFilesystem).
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/files-sdk files-sdk
pnpm add @mastra/files-sdk files-sdk
yarn add @mastra/files-sdk files-sdk
bun add @mastra/files-sdk files-sdk
files-sdk is a peer dependency you configure with the adapter you want to use.
UsageDirect link to Usage
Create a Files instance from FilesSDK with the adapter of your choice, then pass it to FilesSDKFilesystem:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { FilesSDKFilesystem } from '@mastra/files-sdk'
import { Files } from 'files-sdk'
import { s3 } from 'files-sdk/s3'
const files = new Files({
adapter: s3({
bucket: 'my-bucket',
region: 'us-east-1',
}),
})
const workspace = new Workspace({
filesystem: new FilesSDKFilesystem({ files }),
})
const agent = new Agent({
name: 'file-agent',
model: 'anthropic/claude-opus-4-6',
workspace,
})
Swapping adaptersDirect link to Swapping adapters
The same FilesSDKFilesystem works with any FilesSDK adapter. Replace the driver factory to switch backends:
import { Files } from 'files-sdk'
import { r2 } from 'files-sdk/r2'
import { gcs } from 'files-sdk/gcs'
import { azure } from 'files-sdk/azure'
import { fs } from 'files-sdk/fs'
// Cloudflare R2
const r2Files = new Files({ adapter: r2({ accountId, bucket, accessKeyId, secretAccessKey }) })
// Google Cloud Storage
const gcsFiles = new Files({ adapter: gcs({ bucket, projectId }) })
// Azure Blob
const azureFiles = new Files({ adapter: azure({ container, connectionString }) })
// Local filesystem (useful for tests and development)
const localFiles = new Files({ adapter: fs({ root: './workspace' }) })
See the FilesSDK documentation for the full adapter catalog and configuration options.
Read-only mountsDirect link to Read-only mounts
const filesystem = new FilesSDKFilesystem({
files,
readOnly: true,
})
All write operations (writeFile, appendFile, deleteFile, copyFile, moveFile, mkdir, rmdir) throw WorkspaceReadOnlyError while reads succeed.
Constructor parametersDirect link to Constructor parameters
files:
id?:
displayName?:
icon?:
description?:
readOnly?:
PropertiesDirect link to Properties
id:
name:
provider:
readOnly:
MethodsDirect link to Methods
FilesSDKFilesystem 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 directory (no-op for object stores)rmdir(path, options?)- Remove a directoryreaddir(path, options?)- List directory contentsexists(path)- Check if a path existsstat(path)- Get file or directory metadata
init()Direct link to init
Initialize the filesystem. Verifies that the configured adapter can list keys with the supplied credentials.
await filesystem.init()
getInfo()Direct link to getinfo
Returns metadata about this filesystem instance.
const info = filesystem.getInfo()
// { id: '...', name: 'FilesSDKFilesystem', provider: 'files-sdk', status: 'ready' }
filesDirect link to files
The underlying FilesSDK Files instance is exposed as a public property if you need to call adapter-specific APIs directly.
const url = await filesystem.files.url('reports/q3.pdf')
Object-store semanticsDirect link to Object-store semantics
FilesSDKFilesystem treats the configured backend as an object store, even when the underlying adapter is hierarchical (such as fs). This keeps behavior consistent across adapters:
mkdiris a no-op. Directories exist implicitly when keys with that prefix exist.existsreturnstrueonly when an exact key is present as a file, or when the path is a prefix that contains at least one child key. Empty leftover directories on hierarchical adapters do not count.deleteFilethrowsFileNotFoundErrorwhen the key does not exist, unless{ force: true }is passed.deleteFileon a directory delegates tormdir({ recursive: true }), matching theS3FilesystemandGCSFilesystembehavior.moveFileis implemented ascopyFilefollowed bydeleteFile. It is not atomic — if the source delete fails after a successful copy, the destination remains and the source is not removed.appendFileis a read-modify-write operation. Concurrent appends to the same key may overwrite each other; this is inherent to object storage and not specific to FilesSDK.readdir({ recursive: true })emits intermediate directory entries (for example,a/bis emitted alongsidea/b/c.txt).