upload_file
Transfer files from local storage to a specified bucket in MinIO object storage using bucket name, object name, and file path. Optional metadata can be added during the upload process.
Instructions
上传文件到存储桶
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucketName | Yes | 存储桶名称 | |
| filePath | Yes | 本地文件路径 | |
| metadata | No | 文件元数据(可选) | |
| objectName | Yes | 对象名称 |
Implementation Reference
- src/index.ts:415-432 (handler)MCP CallToolRequestSchema handler for 'upload_file' tool: validates input parameters using Zod schema matching the tool's inputSchema, calls MinIOStorageClient.uploadFile method, and returns a success text response.case 'upload_file': { const { bucketName, objectName, filePath, metadata } = z.object({ bucketName: z.string(), objectName: z.string(), filePath: z.string(), metadata: z.record(z.string()).optional() }).parse(args); await this.minioClient.uploadFile(bucketName, objectName, filePath, metadata); return { content: [ { type: 'text', text: `成功上传文件 ${filePath} 到 ${bucketName}/${objectName}` } ] }; }
- src/index.ts:135-148 (registration)Registration of the 'upload_file' tool in the ListToolsRequestSchema handler response, including name, description, and JSON schema for input validation.{ name: 'upload_file', description: '上传文件到存储桶', inputSchema: { type: 'object', properties: { bucketName: { type: 'string', description: '存储桶名称' }, objectName: { type: 'string', description: '对象名称' }, filePath: { type: 'string', description: '本地文件路径' }, metadata: { type: 'object', description: '文件元数据(可选)' } }, required: ['bucketName', 'objectName', 'filePath'] } },
- src/minio-client.ts:106-117 (helper)Core implementation of file upload in MinIOStorageClient: checks file existence, creates read stream, and uses MinIO client's putObject to upload to the specified bucket and object name.async uploadFile(bucketName: string, objectName: string, filePath: string, metadata?: Record<string, string>): Promise<void> { this.ensureConnected(); if (!fs.existsSync(filePath)) { throw new Error(`文件不存在: ${filePath}`); } const stats = fs.statSync(filePath); const stream = fs.createReadStream(filePath); await this.client!.putObject(bucketName, objectName, stream, stats.size, metadata); }