Files
Manage binary files (PDFs, CSVs, images, documents, etc.) attached to your Mentiora project. Files are stored server-side and can be used for analysis, knowledge bases, or any custom workflow.
Upload a File
- TypeScript
- Python
import { readFileSync } from 'fs';
const result = await client.files.upload({
filename: 'report.pdf',
content: readFileSync('./report.pdf'),
mimeType: 'application/pdf',
description: 'Q1 sales report',
});
console.log(`Uploaded: ${result.fileId}`);
Async (recommended):
from mentiora import UploadFileParams
with open('report.pdf', 'rb') as f:
result = await client.files.upload_async(UploadFileParams(
filename='report.pdf',
content=f.read(),
mime_type='application/pdf',
description='Q1 sales report',
))
print(f'Uploaded: {result.file_id}')
Sync:
from mentiora import UploadFileParams
with open('report.pdf', 'rb') as f:
result = client.files.upload(UploadFileParams(
filename='report.pdf',
content=f.read(),
mime_type='application/pdf',
description='Q1 sales report',
))
print(f'Uploaded: {result.file_id}')
The SDK handles base64 encoding automatically. Maximum file size is 50 MB.
List Files
- TypeScript
- Python
// List all files
const files = await client.files.list();
console.log(`Total: ${files.totalCount}`);
for (const file of files.data) {
console.log(`${file.filename} (${file.size} bytes)`);
}
// Search by name or description
const results = await client.files.list({ query: 'report' });
// Paginate
const page2 = await client.files.list({ offset: 10, count: 10 });
Async (recommended):
# List all files
files = await client.files.list_async()
print(f'Total: {files.total_count}')
for file in files.data:
print(f'{file.filename} ({file.size} bytes)')
# Search by name or description
results = await client.files.list_async(query='report')
# Paginate
page2 = await client.files.list_async(offset=10, count=10)
Sync:
files = client.files.list()
results = client.files.list(query='report')
page2 = client.files.list(offset=10, count=10)
Get File Metadata
- TypeScript
- Python
const file = await client.files.get('019d6d5d-d384-7793-9e0f-2592a9986021');
console.log(`${file.filename} — ${file.mimeType} — ${file.size} bytes`);
Async (recommended):
file = await client.files.get_async('019d6d5d-d384-7793-9e0f-2592a9986021')
print(f'{file.filename} — {file.mime_type} — {file.size} bytes')
Sync:
file = client.files.get('019d6d5d-d384-7793-9e0f-2592a9986021')
Download a File
- TypeScript
- Python
const content = await client.files.download('019d6d5d-d384-7793-9e0f-2592a9986021');
// content is a Uint8Array — write to disk or process in memory
import { writeFileSync } from 'fs';
writeFileSync('./downloaded-report.pdf', content);
Async (recommended):
content = await client.files.download_async('019d6d5d-d384-7793-9e0f-2592a9986021')
# content is bytes — write to disk or process in memory
with open('downloaded-report.pdf', 'wb') as f:
f.write(content)
Sync:
content = client.files.download('019d6d5d-d384-7793-9e0f-2592a9986021')
with open('downloaded-report.pdf', 'wb') as f:
f.write(content)
Delete a File
Deletion fails with a 409 Conflict error if the file is still referenced by a knowledge base document. Remove the reference first, then delete.
- TypeScript
- Python
const result = await client.files.delete('019d6d5d-d384-7793-9e0f-2592a9986021');
console.log(`Deleted: ${result.deleted}`);
Async (recommended):
result = await client.files.delete_async('019d6d5d-d384-7793-9e0f-2592a9986021')
print(f'Deleted: {result.deleted}')
Sync:
result = client.files.delete('019d6d5d-d384-7793-9e0f-2592a9986021')
Supported File Types
The platform accepts a wide range of file types including:
- Documents: PDF, DOCX, DOC, ODT, RTF
- Structured data: CSV, TSV, JSON, JSONL, XML, YAML
- Text: TXT, Markdown, HTML
- Images: PNG, JPEG, GIF, WebP, SVG, TIFF, BMP
- Email: EML
- eBooks: EPUB
See Also
- Files API Reference -- full method and type reference
- Authentication -- setting up your API key
- Examples -- complete, runnable code samples