AzureBlobFilesystem
Stores files in Azure Blob Storage containers.
For interface details, see WorkspaceFilesystem Interface.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/azure
pnpm add @mastra/azure
yarn add @mastra/azure
bun add @mastra/azure
UsageDirect link to Usage
Add an AzureBlobFilesystem to a workspace and assign it to an agent:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { AzureBlobFilesystem } from '@mastra/azure/blob'
const workspace = new Workspace({
filesystem: new AzureBlobFilesystem({
container: 'my-container',
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
}),
})
const agent = new Agent({
name: 'file-agent',
model: 'anthropic/claude-opus-4-6',
workspace,
})
Account keyDirect link to Account key
Use an account name and account key when you do not want to pass a full connection string:
import { AzureBlobFilesystem } from '@mastra/azure/blob'
const filesystem = new AzureBlobFilesystem({
container: 'my-container',
accountName: process.env.AZURE_STORAGE_ACCOUNT_NAME,
accountKey: process.env.AZURE_STORAGE_ACCOUNT_KEY,
})
Shared access signature tokenDirect link to Shared access signature token
Use a shared access signature (SAS) token with either accountName or endpoint:
import { AzureBlobFilesystem } from '@mastra/azure/blob'
const filesystem = new AzureBlobFilesystem({
container: 'my-container',
accountName: process.env.AZURE_STORAGE_ACCOUNT_NAME,
sasToken: process.env.AZURE_STORAGE_SAS_TOKEN,
})
DefaultAzureCredentialDirect link to DefaultAzureCredential
Use DefaultAzureCredential when your environment provides Azure identity credentials:
import { AzureBlobFilesystem } from '@mastra/azure/blob'
const filesystem = new AzureBlobFilesystem({
container: 'my-container',
accountName: process.env.AZURE_STORAGE_ACCOUNT_NAME,
useDefaultCredential: true,
})
Install @azure/identity when you use DefaultAzureCredential:
- npm
- pnpm
- Yarn
- Bun
npm install @azure/identity
pnpm add @azure/identity
yarn add @azure/identity
bun add @azure/identity
Constructor parametersDirect link to Constructor parameters
container:
connectionString?:
accountName?:
accountKey?:
sasToken?:
useDefaultCredential?:
endpoint?:
prefix?:
id?:
displayName?:
icon?:
description?:
readOnly?:
PropertiesDirect link to Properties
id:
name:
provider:
readOnly:
MethodsDirect link to Methods
AzureBlobFilesystem 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()Direct link to init
Initialize the filesystem. Verifies container access and credentials.
await filesystem.init()
getInfo()Direct link to getinfo
Returns metadata about this filesystem instance.
const info = filesystem.getInfo()
// { id: '...', name: 'AzureBlobFilesystem', provider: 'azure-blob', status: 'ready' }
getContainer()Direct link to getcontainer
Returns the underlying Azure Blob Storage ContainerClient.
const container = await filesystem.getContainer()
getMountConfig()Direct link to getmountconfig
Returns the mount configuration for sandbox providers that support Azure Blob filesystem mounts.
const config = filesystem.getMountConfig()
// { type: 'azure-blob', container: 'my-container', ... }
Azure Blob sandbox mounting depends on sandbox support for azure-blob mount configs. Use filesystem for direct workspace file operations when your sandbox provider does not support Azure Blob mounts.