upload_file
Upload file content as a string to a specified field in a PocketBase collection record using the required collection, record ID, field name, file name, and content string.
Instructions
Upload a file (provided as content string) to a PocketBase collection record field.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | The name or ID of the collection. | |
| fileContent | Yes | The raw content of the file as a string. | |
| fileField | Yes | The name of the file field in the collection schema. | |
| fileName | Yes | The desired name for the uploaded file (e.g., "report.txt"). | |
| recordId | Yes | The ID of the record to attach the file to. |
Implementation Reference
- src/tools/file-tools.ts:62-81 (handler)The main handler function that performs the file upload to a PocketBase record field using FormData and Blob.async function uploadFile(args: UploadFileArgs, pb: PocketBase): Promise<ToolResult> { if (!args.collection || !args.recordId || !args.fileField || !args.fileContent || !args.fileName) { throw invalidParamsError("Missing required arguments: collection, recordId, fileField, fileContent, fileName"); } // Create a Blob from the file content string // Note: Encoding might be an issue depending on the file type. Assuming UTF-8 for now. const blob = new Blob([args.fileContent]); // Create a FormData object and append the file const formData = new FormData(); formData.append(args.fileField, blob, args.fileName); // Update the record with the file const record = await pb.collection(args.collection).update(args.recordId, formData); return { content: [{ type: 'text', text: `File '${args.fileName}' uploaded successfully to record ${args.recordId}. Updated record:\n${JSON.stringify(record, null, 2)}` }], }; }
- src/types/tool-types.ts:58-64 (schema)TypeScript interface defining the input parameters for the upload_file tool.export interface UploadFileArgs { collection: string; recordId: string; fileField: string; fileContent: string; fileName: string; }
- src/tools/file-tools.ts:13-27 (registration)ToolInfo object registering the upload_file tool with name, description, and input schema.{ name: 'upload_file', description: 'Upload a file (provided as content string) to a PocketBase collection record field.', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'The name or ID of the collection.' }, recordId: { type: 'string', description: 'The ID of the record to attach the file to.' }, fileField: { type: 'string', description: 'The name of the file field in the collection schema.' }, fileContent: { type: 'string', description: 'The raw content of the file as a string.' }, fileName: { type: 'string', description: 'The desired name for the uploaded file (e.g., "report.txt").' } }, required: ['collection', 'recordId', 'fileField', 'fileContent', 'fileName'] }, },
- src/tools/file-tools.ts:48-58 (helper)Helper function that dispatches tool calls to specific handlers, including upload_file.// Handle calls for file-related tools export async function handleFileToolCall(name: string, args: any, pb: PocketBase): Promise<ToolResult> { switch (name) { case 'upload_file': return uploadFile(args as UploadFileArgs, pb); case 'download_file': return downloadFile(args as DownloadFileArgs, pb); default: throw new Error(`Unknown file tool: ${name}`); } }
- src/tools/index.ts:49-50 (registration)Top-level tool call dispatcher that routes upload_file calls to the file tools handler.} else if (name === 'upload_file' || name === 'download_file') { return handleFileToolCall(name, toolArgs, pb);