Skip to main content
Glama

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
NameRequiredDescriptionDefault
sourceYesThe source media to upload (URL, file path, base64 content, or binary data)
folderNoOptional folder path in Cloudinary
publicIdNoOptional public ID for the uploaded asset
resourceTypeNoType of resource to uploadauto
tagsNoA string containing Comma-separated list of tags to assign to the asset

Implementation Reference

  • 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); } }
  • 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), );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yoavniran/cloudinary-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server