upload-files
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUpload Files to ImageKit
向ImageKit上传文件
CRITICAL: Only URL-based uploads are supported
关键注意事项:仅支持基于URL的上传
The parameter must be a publicly accessible URL string. Local files cannot be uploaded — local paths, Buffers, and streams are not supported and will fail. If the user has a local file, they must first host it at a public URL and pass that URL.
fileBoth and are required.
filefileNameNEVER convert a local file to a base64 (data URI) string and try to upload it. Reading a file into the model context to base64-encode it burns a huge number of LLM tokens and still won't work for large files. Always pass a URL — never inline file bytes.
Uploads are performed with the SDK's method via .
client.files.upload()mcp_imagekit_api_executefilefilefileName切勿将本地文件转换为base64(数据URI)字符串尝试上传。将文件读取到模型上下文进行base64编码会消耗大量LLM令牌,且大文件仍无法上传。始终传入URL——绝不直接嵌入文件字节。
上传操作通过调用SDK的方法完成。
mcp_imagekit_api_executeclient.files.upload()Usage
使用示例
typescript
async function run(client) {
const file = await client.files.upload({
file: 'https://example.com/photo.jpg', // URL string ONLY — no local paths
fileName: 'photo.jpg',
folder: '/products',
tags: ['product', 'featured'],
});
return { fileId: file.fileId, url: file.url, size: file.size, fileType: file.fileType };
}typescript
async function run(client) {
const file = await client.files.upload({
file: 'https://example.com/photo.jpg', // 仅支持URL字符串——不允许本地路径
fileName: 'photo.jpg',
folder: '/products',
tags: ['product', 'featured'],
});
return { fileId: file.fileId, url: file.url, size: file.size, fileType: file.fileType };
}Parameters
参数说明
Parameter names mirror the Upload API () field names in camelCase. When a field is omitted, ImageKit applies its own default.
FileUploadV1| Parameter | Description |
|---|---|
| Publicly accessible URL of the file to upload. Local paths are NOT allowed. |
| Name for the uploaded file, e.g. |
| Destination folder in ImageKit (default: |
| Array of tags (e.g. |
| Mark file as private |
| Publish the file; |
| Add a unique suffix to the filename (default |
| Overwrite an existing file at the same path |
| Overwrite existing AITags when replacing |
| Overwrite existing tags when replacing |
| Overwrite existing customMetadata when replacing |
| Description for the file |
| Important area: |
| Object of custom metadata, e.g. |
| Array of extensions, e.g. |
| Object of pre/post transformations, e.g. |
| URL to receive extension completion status |
| Fields to include in the response (e.g. |
| Server-side upload check expression |
参数名称与Upload API()的字段名称一致,采用小驼峰命名法。若省略字段,ImageKit将应用其默认值。
FileUploadV1| 参数 | 说明 |
|---|---|
| 待上传文件的可公开访问URL。不允许使用本地路径。 |
| 上传后的文件名,例如 |
| ImageKit中的目标文件夹(默认值: |
| 标签数组(例如 |
| 将文件标记为私有 |
| 发布文件;设为 |
| 为文件名添加唯一后缀(默认值 |
| 覆盖同一路径下的现有文件 |
| 替换文件时覆盖现有AITags |
| 替换文件时覆盖现有标签 |
| 替换文件时覆盖现有自定义元数据 |
| 文件描述 |
| 重点区域: |
| 自定义元数据对象,例如 |
| 扩展功能数组,例如 |
| 预处理/后处理转换配置,例如 |
| 接收扩展功能完成状态的URL |
| 响应中需包含的字段(例如 |
| 服务器端上传校验表达式 |
Examples
更多示例
typescript
// Basic upload to a folder with tags
await client.files.upload({
file: 'https://example.com/photo.jpg',
fileName: 'photo.jpg',
folder: '/products',
tags: ['product', 'featured'],
});
// Overwrite an exact-named file
await client.files.upload({
file: 'https://example.com/banner.jpg',
fileName: 'banner.jpg',
useUniqueFileName: false,
overwriteFile: true,
});
// Upload with auto-tagging extension
await client.files.upload({
file: 'https://example.com/photo.jpg',
fileName: 'photo.jpg',
extensions: [{ name: 'google-auto-tagging', maxTags: 5 }],
});
// Upload with custom metadata and a pre-transformation
await client.files.upload({
file: 'https://example.com/photo.jpg',
fileName: 'photo.jpg',
customMetadata: { brand: 'Nike' },
transformation: { pre: 'w-1200,q-80' },
});typescript
// 基础上传:指定文件夹并添加标签
await client.files.upload({
file: 'https://example.com/photo.jpg',
fileName: 'photo.jpg',
folder: '/products',
tags: ['product', 'featured'],
});
// 覆盖同名文件
await client.files.upload({
file: 'https://example.com/banner.jpg',
fileName: 'banner.jpg',
useUniqueFileName: false,
overwriteFile: true,
});
// 上传时启用自动标签扩展
await client.files.upload({
file: 'https://example.com/photo.jpg',
fileName: 'photo.jpg',
extensions: [{ name: 'google-auto-tagging', maxTags: 5 }],
});
// 上传时添加自定义元数据并配置预处理
await client.files.upload({
file: 'https://example.com/photo.jpg',
fileName: 'photo.jpg',
customMetadata: { brand: 'Nike' },
transformation: { pre: 'w-1200,q-80' },
});Notes
注意事项
- Local files cannot be uploaded. Only a publicly accessible URL works. If the user provides a local path, tell them to host it publicly first and share the URL.
- is the ImageKit media library path (not local). Starts with
folder, auto-creates nested folders. Don't include the filename in the folder path./ - allows:
fileName,a-z,A-Z,0-9,.. Other characters become-._ - defaults to
useUniqueFileName(a unique suffix is appended). To overwrite an exact-named file, settrueanduseUniqueFileName: false.overwriteFile: true - fields must be created in the DAM first.
customMetadata
- 无法上传本地文件:仅可使用可公开访问的URL。若用户提供本地路径,请告知其先将文件托管到公开地址并提供URL。
- 是ImageKit媒体库中的路径(非本地路径)。以
folder开头,会自动创建嵌套文件夹。请勿在文件夹路径中包含文件名。/ - 允许使用:
fileName、a-z、A-Z、0-9、.。其他字符会被替换为-。_ - 默认值为
useUniqueFileName(会追加唯一后缀)。若要覆盖同名文件,请设置true并开启useUniqueFileName: false。overwriteFile: true - 的字段需先在DAM中创建。
customMetadata
Procedure
操作流程
- Get a public URL: Confirm the file is available at a publicly accessible URL. If the user has only a local file, stop and ask them to host it and provide the URL.
- Decide folder and tags: Where in the ImageKit media library the file should live.
- Run the upload via using
mcp_imagekit_api_execute.client.files.upload() - Verify the response: Confirm a and
fileIdare returned and the reportedurl/sizematch (fileTypeisfileTypefor images,imagefor video and other files).non-image
- 获取公开URL:确认文件可通过公开URL访问。若用户仅有本地文件,请暂停操作并要求其先托管文件并提供URL。
- 确定文件夹与标签:指定文件在ImageKit媒体库中的存储位置及标签。
- 执行上传:通过调用
mcp_imagekit_api_execute完成上传。client.files.upload() - 验证响应:确认返回结果包含和
fileId,且url/size与预期匹配(图片的fileType为fileType,视频及其他文件为image)。non-image
Error Prevention
错误预防
- Local paths fail: Passing a local file path, Buffer, or stream is not supported — always pass a URL string.
- Never base64-encode a file to upload it: Converting a local file to a base64/data-URI string wastes LLM tokens and fails for large files. Host the file and pass its URL instead.
- File size limits: Free plan: 25MB images, 100MB videos. Paid plans: higher.
- Version limit: Max 100 versions per file.
- 本地路径会导致失败:不支持传入本地文件路径、Buffer或流——始终传入URL字符串。
- 绝不要通过base64编码上传文件:将本地文件转换为base64/数据URI字符串会浪费LLM令牌,且大文件无法上传。请先托管文件再传入其URL。
- 文件大小限制:免费版:图片最大25MB,视频最大100MB。付费版限制更高。
- 版本限制:每个文件最多支持100个版本。