Vercel Files
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).
InstallationInstallation的直接链接
- 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.
UsageUsage的直接链接
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({
id: 'file-agent',
name: 'file-agent',
model: 'anthropic/claude-opus-4-7',
workspace,
})
Swapping adaptersSwapping 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 mountsRead-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 parametersConstructor parameters的直接链接
files:
Files instance bound to the adapter and credentials you want to use.id?:
displayName?:
icon?:
description?:
readOnly?:
PropertiesProperties的直接链接
id:
name:
provider:
readOnly:
MethodsMethods的直接链接
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()init的直接链接
Initialize the filesystem. Verifies that the configured adapter can list keys with the supplied credentials.
await filesystem.init()
getInfo()getinfo的直接链接
Returns metadata about this filesystem instance.
const info = filesystem.getInfo()
// { id: '...', name: 'FilesSDKFilesystem', provider: 'files-sdk', status: 'ready' }
filesfiles的直接链接
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 semanticsObject-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 don't count.deleteFilethrowsFileNotFoundErrorwhen the key doesn't exist, unless{ force: true }is passed.deleteFileon a directory delegates tormdir({ recursive: true }), matching theS3FilesystemandGCSFilesystembehavior.moveFileis implemented ascopyFilefollowed bydeleteFile. It isn't atomic. If the source delete fails after a successful copy, the destination remains and the source isn't 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).