upload
Upload files to Cloudinary from URLs, file paths, or binary data, organizing them with folders, tags, and custom IDs for media management.
Instructions
Upload a file (asset) to Cloudinary
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | The source media to upload (URL, file path, base64 content, or binary data) | |
| folder | No | Optional folder path in Cloudinary | |
| publicId | No | Optional public ID for the uploaded asset | |
| resourceType | No | Type of resource to upload | auto |
| tags | No | A string containing Comma-separated list of tags to assign to the asset |
Implementation Reference
- src/tools/uploadTool.js:17-61 (handler)Core handler function that executes the upload logic to Cloudinary, handling different source types (string URL/path/base64 or Buffer) using uploader.upload or upload_stream.const uploadTool = async (cloudinary, { source, folder, publicId, resourceType, tags }) => { try { const uploadOptions = { resource_type: resourceType, folder, public_id: publicId, tags, }; let uploadResult; // Handle different source types if (typeof source === 'string') { uploadResult = await cloudinary.uploader.upload(source, uploadOptions); } else if (Buffer.isBuffer(source)) { // Handle Buffer data uploadResult = await new Promise((resolve, reject) => { const uploadStream = cloudinary.uploader.upload_stream( uploadOptions, (error, result) => { if (error) { return reject(error); } resolve(result); } ); uploadStream.end(source); }); } else { throw new Error("unknown source type: " + typeof source); } return { content: [ { type: "text", text: JSON.stringify(uploadResult, null, 2) } ], isError: false, }; } catch (error) { return getToolError(`Error uploading to Cloudinary: ${error.message}`, cloudinary); } }
- src/tools/uploadTool.js:5-15 (schema)Zod schema defining the input parameters for the upload tool.export const uploadToolParams = { source: z.union([ z.string().url().describe("URL of the image/video to upload"), z.string().describe("Base64 encoded file content or file path"), z.instanceof(Buffer).describe("Binary data to upload") ]).describe("The source media to upload (URL, file path, base64 content, or binary data)"), folder: z.string().optional().describe("Optional folder path in Cloudinary"), publicId: z.string().optional().describe("Optional public ID for the uploaded asset"), resourceType: z.enum(["image", "video", "raw", "auto"]).default("auto").describe("Type of resource to upload"), tags: z.string().optional().describe("A string containing Comma-separated list of tags to assign to the asset"), };
- src/index.js:37-42 (registration)MCP server tool registration for the 'upload' tool, providing name, description, input schema, and wrapped handler.server.tool( "upload", "Upload a file (asset) to Cloudinary", uploadToolParams, getUploadTool(cloudinary), );