# Upload Image — ImageKit.io

> Upload a new image to ImageKit.io. See the documentation

- Key: `imagekit_io-upload-image`
- Type: Action (Write)
- Version: 1.0.4
- App: ImageKit.io (`imagekit_io`) — https://pipedream.com/apps/imagekit-io.md
- This page (HTML): https://pipedream.com/apps/imagekit-io/actions/upload-image
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/imagekit_io/actions/upload-image/upload-image.mjs

## Description

Upload a new image to ImageKit.io. [See the documentation](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `file` | `string` | Yes | The file to upload. Provide a file URL or a path to a file in the /tmp directory. This can be a binary file or a base64-encoded string. |
| `fileName` | `string` | Yes | The name with which the file has to be uploaded. The file name can contain: - Alphanumeric Characters: a-z , A-Z , 0-9 (including unicode letters, marks, and numerals in other languages) - Special Characters: . and - Any other character including space will be replaced by _ |
| `useUniqueFileName` | `boolean` | No | Whether to use a unique filename for this file or not. If set true, ImageKit.io will add a unique suffix to the filename parameter to get a unique filename. If set false, then the image is uploaded with the provided filename parameter, and any existing file with the same name is replaced. Default Value is True |
| `tags` | `string[]` | No | Set the tags while uploading the file. % is not allowed. If this field is not specified and the file is overwritten then the tags will be removed. |
| `folder` | `string` | No | The folder path (e.g. /images/folder/) in which the image has to be uploaded. If the folder(s) didn't exist before, a new folder(s) is created. The nesting of folders can be at most 50 levels deep. The folder name can contain: - Alphanumeric Characters: a-z , A-Z , 0-9 (including unicode letters, marks, and numerals in other languages). - Special Characters: /, _ and -. - Using multiple / creates a nested folder. |
| `isPrivateFile` | `boolean` | No | Whether to mark the file as private or not. This is only relevant for image type files. |
| `isPublished` | `boolean` | No | Whether to upload file as published or not. If set false, the file is marked as unpublished, which restricts access to the file only via the media library. Files in draft or unpublished state can only be publicly accessed after being published. - The option to upload in draft state is only available in custom enterprise pricing plans. |
| `customCoordinates` | `string` | No | Define an important area in the image. This is only relevant for image type files. The the format x,y,width,height. For example - 10,10,100,100. |
| `responseFields` | `string[]` | No | A list of the fields that you want the API to return in the response. For example, set the value of this field to tags, customCoordinates, isPrivateFile to get the value of tags, customCoordinates, isPublished and isPrivateFile in the response. Accepts combination of tags, customCoordinates, isPrivateFile, embeddedMetadata, customMetadata, and metadata. |
| `extensions` | `string[]` | No | An array of stringified object extensions to be applied to the image. For reference about extensions read here. |
| `webhookUrl` | `string` | No | The final status of pending extensions will be sent to this URL. To learn more about how ImageKit uses webhooks, refer here. |
| `overwriteFile` | `boolean` | No | Default is true. If overwriteFile is set to false and useUniqueFileName is also false, and a file already exists at the exact location, upload API will return an error immediately. |
| `overwriteAITags` | `boolean` | No | Default is true. If the request does not have tags, overwriteTags is set to true and a file already exists at the exact location, exiting tags will be removed. In case the request body has tags, setting overwriteTags to false has no effect and request's tags are set on the asset. |
| `overwriteCustomMetadata` | `boolean` | No | Default is true. If the request does not have customMetadata, overwriteCustomMetadata is set to true and a file already exists at the exact location, exiting customMetadata will be removed. In case the request body has customMetadata, setting overwriteCustomMetadata to false has no effect and request's customMetadata is set on the asset. |
| `customMetadata` | `object` | No | A JSON key-value data to be associated with the asset. Checkout overwriteCustomMetadata parameter to understand default behaviour. Before setting any custom metadata on an asset you have to create the field using custom metadata fields API. |
| `syncDir` | `dir` | No | SyncDir |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "imagekit_io",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "imagekit_io-upload-image",
  arguments: {
    file: "File Path or URL",
    fileName: "File Name",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "imagekit_io-upload-image",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    imagekit_io: { authProvisionId: "apn_xxxxxxx" },
    file: "File Path or URL",
    fileName: "File Name",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "imagekit_io-upload-image",
    "configured_props": {
      "imagekit_io": { "authProvisionId": "apn_xxxxxxx" },
      "file": "File Path or URL",
      "fileName": "File Name"
    }
  }'
```

---

- App: https://pipedream.com/apps/imagekit-io.md · All apps: https://pipedream.com/apps
