Skip to main content
Glama

upload_file

Upload files to web pages by specifying a file input element and local file path for browser automation and testing.

Instructions

Upload a file through a provided element.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesThe uid of the file input element or an element that will open file chooser on the page from the page content snapshot
filePathYesThe local path of the file to upload

Implementation Reference

  • The handler function that implements the logic for the 'upload_file' tool. It uploads a file to the specified element (file input or clickable element triggering file chooser).
    handler: async (request, response, context) => { const {uid, filePath} = request.params; const handle = (await context.getElementByUid( uid, )) as ElementHandle<HTMLInputElement>; try { try { await handle.uploadFile(filePath); } catch { // Some sites use a proxy element to trigger file upload instead of // a type=file element. In this case, we want to default to // Page.waitForFileChooser() and upload the file this way. try { const page = context.getSelectedPage(); const [fileChooser] = await Promise.all([ page.waitForFileChooser({timeout: 3000}), handle.asLocator().click(), ]); await fileChooser.accept([filePath]); } catch { throw new Error( `Failed to upload file. The element could not accept the file directly, and clicking it did not trigger a file chooser.`, ); } } response.setIncludeSnapshot(true); response.appendResponseLine(`File uploaded from ${filePath}.`); } finally { void handle.dispose(); } },
  • Input schema for the 'upload_file' tool using Zod, defining 'uid' and 'filePath' parameters.
    schema: { uid: z .string() .describe( 'The uid of the file input element or an element that will open file chooser on the page from the page content snapshot', ), filePath: z.string().describe('The local path of the file to upload'), },
  • src/main.ts:307-320 (registration)
    Registration of all tools, including 'upload_file' from inputTools (imported as * from './tools/input.js' on line 32), by collecting Object.values(inputTools) into the tools array and calling registerTool for each.
    const tools = [ ...Object.values(consoleTools), ...Object.values(emulationTools), ...Object.values(inputTools), ...Object.values(networkTools), ...Object.values(pagesTools), ...Object.values(performanceTools), ...Object.values(screenshotTools), ...Object.values(scriptTools), ...Object.values(snapshotTools), ]; for (const tool of tools) { registerTool(tool as unknown as ToolDefinition); }

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/SHAY5555-gif/chrome-devtools-mcp'

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