Server side file upload
You can upload files to the ImageKit.io media library from your server-side using private API key authentication.
File size limit The maximum upload file size is limited to 25MB.

Endpoint

Request structure (multipart/form-data)

Parameter
Description
file required
This field accepts three kinds of values: - binary - You can send the content of the file as binary. This is used when a file is being uploaded from the browser. - base64 - Base64 encoded string of file content. - url - URL of the file from where to download the content before uploading. For example - https://www.example.com/rest-of-the-image-path.jpg.
Note: When passing a URL in the file parameter, please ensure that our servers can access the URL. In case ImageKit is unable to download the file from the specified URL, a 400 error response is returned. In addition to this, the file download request is aborted if response headers are not received in 8 seconds. This will also result in a 400 error.
fileName required
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 optional
Whether to use a unique filename for this file or not. - Accepts true or false. - 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 - true
tags optional
Set the tags while uploading the file. - Comma-separated value of tags in the format tag1,tag2,tag3. For example - t-shirt,round-neck,men - The maximum length of all characters should not exceed 500. - % is not allowed. - If this field is not specified and the file is overwritten then the tags will be removed.
folder optional
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 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. Default value - /
isPrivateFile optional
Whether to mark the file as private or not. This is only relevant for image type files. - Accepts true or false. - If set true, the file is marked as private which restricts access to the original image URL and unnamed image transformations without signed URLs. Without the signed URL, only named transformations work on private images Default value - false
customCoordinates optional
Define an important area in the image. This is only relevant for image type files.
  • To be passed as a string with the x and y coordinates of the top-left corner, and width and height of the area of interest in the format x,y,width,height. For example - 10,10,100,100
  • Can be used with fo-customtransformation.
  • If this field is not specified and the file is overwritten, then customCoordinates will be removed.
responseFields optional
Comma-separated values 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, and isPrivateFile in the response. Accepts combination of tags, customCoordinates, isPrivateFile, embeddedMetadata, and customMetadata.
extensions
optional
Stringified JSON object with an array of extensions to be applied to the image.
For reference about extensions read here.
webhookUrl
optional
The final status of pending extensions will be sent to this URL. To learn more about how ImageKit uses webhooks, refer here.
overwriteFile
optional
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
optional
Default is true. If set to true and a file already exists at the exact location, its AITags will be removed. Set overwriteAITags to false to preserve AITags.
overwriteTags
optional
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
optional
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
optional
Stringified 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.

Response code and structure (JSON)

In case of an error, you will get an error code along with the error message. On successful upload, you will receive a 200 status code with uploaded file details in a JSON-encoded response body.
1
{
2
"fileId": "598821f949c0a938d57563bd",
3
"name": "file1.jpg",
4
"url": "https://ik.imagekit.io/your_imagekit_id/images/products/file1.jpg",
5
"thumbnailUrl": "https://ik.imagekit.io/your_imagekit_id/tr:n-media_library_thumbnail/images/products/file1.jpg",
6
"height": 300,
7
"width": 200,
8
"size": 83622,
9
"filePath": "/images/products/file1.jpg",
10
"tags": ["t-shirt", "round-neck", "sale2019"],
11
"AITags": [
12
{
13
"name": "Shirt",
14
"confidence": 90.12,
15
"source": "google-auto-tagging"
16
},
17
/* ... more googleVision tags ... */
18
],
19
"isPrivateFile": false,
20
"customCoordinates": null,
21
"customMetadata": {
22
brand: "Nike",
23
color: "red"
24
},
25
"embeddedMetadata": {
26
Title: "The Title (ref2019.1)",
27
Description: "The description aka caption (ref2019.1)",
28
State: "Province/State(Core)(ref2019.1)",
29
Copyright: "Copyright (Notice) 2019.1 IPTC - www.iptc.org (ref2019.1)"
30
},
31
"extensionStatus": {
32
"google-auto-tagging": "success",
33
"aws-auto-tagging": "pending"
34
},
35
"fileType": "image"
36
}
Copied!

Understanding response

The JSON-encoded response contains details of the uploaded file which can have the following properties:
Property name
Description
fileId
Unique fileId. Store this fileld in your database, as this will be used to perform update action on this file
type
Type of item. It can be either file or folder.
name
Name of the file or folder.
filePath
The relative path of the file. In the case of an image, you can use this path to construct different transformations.
tags
The array of tags associated with the image. If no tags are set, it will be null.
AITags
Array of AITags associated with the image. If no AITags are set, it will be null. These tags can be added using the google-auto-tagging or aws-auto-tagging extensions.
isPrivateFile
Is the file marked as private. It can be either true or false.
customCoordinates
Value of custom coordinates associated with the image in the format x,y,width,height. If customCoordinates are not defined, then it is null.
url
A publicly accessible URL of the file.
thumbnail
In the case of an image, a small thumbnail URL.
fileType
The type of file could be either image or non-image.
mime
MIME Type of the file. For example - image/jpeg
height
Height of the image in pixels (Only for images)
width
Width of the image in pixels (Only for Images)
size
Size of the image file in Bytes
hasAlpha
A boolean indicating if the image has an alpha layer or not.
customMetadata
A key-value data associated with the asset. Use responseField in API request to get customMetadata in the upload API response. Before setting any custom metadata on an asset, you have to create the field using custom metadata fields API.
embeddedMetadata
Consolidated embedded metadata associated with the file. It includes exif, iptc, and xmp data. Use responseField in API request to get embeddedMetadata in the upload API response.
createdAt
The date and time when the file was first uploaded. The format is YYYY-MM-DDTHH:mm:ss.sssZ
updatedAt
The date and time when the file was last updated. The format is YYYY-MM-DDTHH:mm:ss.sssZ
extensionStatus
Extension names with their processing status at the time of completion of the request. It could have one of the following status values:
  • success: The extension has been successfully applied.
  • failed: The extension has failed and will not be retried.
  • pending: The extension will finish processing in some time. On completion, the final status (success / failed) will be sent to the webhookUrl provided.
If no extension was requested, then this parameter is not returned.

Examples

Here are some example requests and responses to understand the API usage.

Uploading file from file system

cURL
Node.js
Python
PHP
Java
Ruby
1
curl -X POST "https://upload.imagekit.io/api/v1/files/upload" \
2
-u your_private_api_key: \
3
-F '[email protected]/Users/username/Desktop/my_file_name.jpg;type=image/jpg' \
4
-F 'fileName=my_file_name.jpg'
Copied!
1
var ImageKit = require("imagekit");
2
var fs = require('fs');
3
​
4
var imagekit = new ImageKit({
5
publicKey : "your_public_key",
6
privateKey : "your_private_key",
7
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
8
});
9
​
10
fs.readFile('image.jpg', function(err, data) {
11
if (err) throw err; // Fail if the file can't be read.
12
imagekit.upload({
13
file : data, //required
14
fileName : "my_file_name.jpg", //required
15
tags: ["tag1", "tag2"]
16
}, function(error, result) {
17
if(error) console.log(error);
18
else console.log(result);
19
});
20
});
Copied!
1
import base64
2
import os
3
import sys
4
from imagekitio import ImageKit
5
​
6
imagekit = ImageKit(
7
public_key='your_public_key',
8
private_key='your_private_key',
9
url_endpoint = 'your_url_endpoint'
10
)
11
​
12
upload = imagekit.upload(
13
file=open("image.jpg", "rb"),
14
file_name="my_file_name.jpg",
15
options={
16
"response_fields": ["is_private_file", "tags"],
17
"tags": ["tag1", "tag2"]
18
},
19
)
20
​
21
print("Upload binary", upload)
Copied!
1
use ImageKit\ImageKit;
2
​
3
$public_key = "your_public_key";
4
$your_private_key = "your_private_key";
5
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
6
$sample_file_path = "/sample.jpg";
7
​
8
$imageKit = new ImageKit(
9
$public_key,
10
$your_private_key,
11
$url_end_point
12
);
13
​
14
// Upload Image - Binary
15
$uploadFile = $imageKit->upload(array(
16
'file' => fopen(__DIR__."/image.jpg", "r"),
17
'fileName' => "my_file_name.jpg",
18
"tags" => implode(",", array("tag1", "tag2")),
19
"customCoordinates" => implode(",", array("10", "10", "100", "100"))
20
));
21
​
22
echo ("Upload binary file : " . json_encode($uploadFile));
Copied!
1
byte[] bytes= Files.readAllBytes(Paths.get("/path/to/file.jpg"));
2
FileCreateRequest fileCreateRequest =new FileCreateRequest(bytes, "sample_image.jpg");
3
fileCreateRequest.setUseUniqueFileName(false);
4
Result result = ImageKit.getInstance().upload(fileCreateRequest);
Copied!
1
imagekitio = ImageKit::ImageKitClient.new("your_private_key", "your_public_key", "your_url_endpoint")
2
file = open("sample.jpg", "rb")
3
upload = imagekitio.upload_file(file, "testing.jpg", {
4
response_fields: 'tags,customCoordinates,isPrivateFile,metadata',
5
tags: %w[abc def],
6
use_unique_file_name: false,
7
is_private_file: true
8
})
Copied!

Uploading base64 encoded file with some tags

cURL
Node.js
Python
PHP
Java
Ruby
1
curl -X POST "https://upload.imagekit.io/api/v1/files/upload" \
2
-u your_private_api_key: \
3
-F 'file=iVBORw0KGgoAAAAN' \
4
-F 'fileName=my_file_name.jpg' \
5
-F 'tags=t-shirt,summer,men'
Copied!
1
var ImageKit = require("imagekit");
2
var fs = require('fs');
3
​
4
var imagekit = new ImageKit({
5
publicKey : "your_public_api_key",
6
privateKey : "your_private_api_key",
7
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
8
});
9
​
10
var base64Img = "iVBORw0KGgoAAAAN";
11
​
12
imagekit.upload({
13
file : base64Img, //required
14
fileName : "my_file_name.jpg", //required
15
tags: ["t-shirt","summer","men"]
16
}, function(error, result) {
17
if(error) console.log(error);
18
else console.log(result);
19
});
Copied!
1
import base64
2
import os
3
import sys
4
from imagekitio import ImageKit
5
​
6
imagekit = ImageKit(
7
public_key='your public_key',
8
private_key='your private_key',
9
url_endpoint = 'your url_endpoint'
10
)
11
​
12
with open("image.jpg", mode="rb") as img:
13
imgstr = base64.b64encode(img.read())
14
​
15
upload = imagekit.upload(
16
file=imgstr,
17
file_name="my_file_name.jpg",
18
options={
19
"response_fields": ["is_private_file", "tags"],
20
"tags": ["t-shirt", "summer","men"]
21
},
22
)
23
​
24
print("Upload base64", upload)
Copied!
1
use ImageKit\ImageKit;
2
​
3
$public_key = "your_public_key";
4
$your_private_key = "your_private_key";
5
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
6
$sample_file_path = "/sample.jpg";
7
​
8
$imageKit = new ImageKit(
9
$public_key,
10
$your_private_key,
11
$url_end_point
12
);
13
​
14
$base64Img = "iVBORw0KGgoAAAAN";
15
​
16
// Upload Image - base64
17
$uploadFile = $imageKit->upload(array(
18
'file' => $base64Img,
19
'fileName' => "my_file_name.jpg",
20
"tags" => implode(",", array("t-shirt", "summer", "men"))
21
));
22
​
23
echo ("Upload base64" . json_encode($uploadFile));
Copied!
1
FileCreateRequest fileCreateRequest =new FileCreateRequest(base64, "sample_base64_image.jpg");
2
Result result = ImageKit.getInstance().upload(fileCreateRequest);
Copied!
1
imagekitio = ImageKitIo::Client.new("your_private_key", "your_public_key", "your_url_endpoint")
2
​
3
image64 = Base64.encode64(File.open("sample.jpg", "rb").read)
4
​
5
upload = imagekitio.upload_file(
6
file: image64,
7
file_name: "testing",
8
response_fields: 'tags,customCoordinates,isPrivateFile,metadata',
9
tags: %w[abc def],
10
use_unique_file_name: true
11
)
Copied!

Uploading file via URL

cURL
Node.js
Python
PHP
Java
Ruby
1
curl -X POST "https://upload.imagekit.io/api/v1/files/upload" \
2
-u your_private_api_key: \
3
-F 'file=https://imagekit.io/image.jpg' \
4
-F 'fileName=my_file_name.jpg'
Copied!
1
var ImageKit = require("imagekit");
2
var fs = require('fs');
3
​
4
var imagekit = new ImageKit({
5
publicKey : "your_public_api_key",
6
privateKey : "your_private_api_key",
7
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
8
});
9
​
10
imagekit.upload({
11
file : "https://imagekit.io/image.jpg", //required
12
fileName : "my_file_name.jpg" //required
13
}, function(error, result) {
14
if(error) console.log(error);
15
else console.log(result);
16
});
Copied!
1
import base64
2
import os
3
import sys
4
from imagekitio import ImageKit
5
​
6
imagekit = ImageKit(
7
public_key='your public_key',
8
private_key='your private_key',
9
url_endpoint = 'your url_endpoint'
10
)
11
​
12
with open("image.jpg", mode="rb") as img:
13
imgstr = base64.b64encode(img.read())
14
​
15
upload = imagekit.upload(
16
file="https://imagekit.io/image.jpg",
17
file_name="my_file_name.jpg",
18
options={},
19
)
20
​
21
print("Upload url", upload)
Copied!
1
use ImageKit\ImageKit;
2
​
3
$public_key = "your_public_key";
4
$your_private_key = "your_private_key";
5
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
6
$sample_file_path = "/sample.jpg";
7
​
8
$imageKit = new ImageKit(
9
$public_key,
10
$your_private_key,
11
$url_end_point
12
);
13
​
14
// Upload Image - URL
15
$uploadFile = $imageKit->upload(array(
16
'file' => "https://imagekit.io/image.jpg",
17
'fileName' => "my_file_name.jpg"
18
));
19
​
20
echo ("Upload URL" . json_encode($uploadFile));
Copied!
1
FileCreateRequest fileCreateRequest = new FileCreateRequest("image_url", "my_file_name.jpg");
2
Result result = ImageKit.getInstance().upload(fileCreateRequest);
Copied!
1
imagekitio = ImageKit::ImageKitClient.new("your_private_key", "your_public_key", "your_url_endpoint")
2
​
3
upload = imagekitio.upload_file(
4
file: "image-url",
5
file_name: "testing"
6
)
Copied!

Setting custom metadata during upload

cURL
Node.js
Python
PHP
Ruby
1
curl -X POST "https://upload.imagekit.io/api/v1/files/upload" \
2
-u your_private_api_key: \
3
-F 'file=https://ik.imagekit.io/ikmedia/red_dress_woman.jpeg' \
4
-F 'fileName=women_in_red.jpg' \
5
-F 'customMetadata={"brand":"Nike", "color":"red"}'
Copied!
1
var ImageKit = require("imagekit");
2
var fs = require('fs');
3
​
4
var imagekit = new ImageKit({
5
publicKey : "your_public_api_key",
6
privateKey : "your_private_api_key",
7
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
8
});
9
​
10
imagekit.upload({
11
file : "https://ik.imagekit.io/ikmedia/red_dress_woman.jpeg",
12
fileName : "women_in_red.jpg",
13
customMetadata : '{"brand":"Nike", "color":"red"}'
14
}, function(error, result) {
15
if(error) console.log(error);
16
else console.log(result);
17
});
Copied!
1
import base64
2
import os
3
import sys
4
from imagekitio import ImageKit
5
​
6
imagekit = ImageKit(
7
public_key='your public_key',
8
private_key='your private_key',
9
url_endpoint = 'your url_endpoint'
10
)
11
​
12
with open("image.jpg", mode="rb") as img:
13
imgstr = base64.b64encode(img.read())
14
​
15
upload = imagekit.upload(
16
file="https://ik.imagekit.io/ikmedia/red_dress_woman.jpeg",
17
file_name="women_in_red.jpg",
18
options={
19
"customMetadata" : '{"brand":"Nike", "color":"red"}'
20
},
21
)
22
​
23
print("Upload url", upload)
Copied!
1
use ImageKit\ImageKit;
2
​
3
$public_key = "your_public_key";
4
$your_private_key = "your_private_key";
5
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
6
$sample_file_path = "/sample.jpg";
7
​
8
$imageKit = new ImageKit(
9
$public_key,
10
$your_private_key,
11
$url_end_point
12
);
13
​
14
// Upload Image - URL
15
$uploadFile = $imageKit->upload(array(
16
'file' => "https://ik.imagekit.io/ikmedia/red_dress_woman.jpeg",
17
'fileName' => "women_in_red.jpg",
18
'customMetadata' => '{"brand":"Nike", "color":"red"}'
19
));
20
​
21
echo ("Upload URL" . json_encode($uploadFile));
Copied!
1
imagekitio = ImageKitIo::Client.new("your_private_key", "your_public_key", "your_url_endpoint")
2
upload = imagekitio.upload_file(
3
file: "https://ik.imagekit.io/ikmedia/red_dress_woman.jpeg",
4
file_name: "women_in_red.jpg",
5
custom_metadata: {
6
"brand":"Nike", "color":"red"
7
}
8
)
Copied!

Applying extensions while uploading

cURL
Node.js
1
curl -X POST "https://upload.imagekit.io/api/v1/files/upload" \
2
-u your_private_api_key: \
3
-F '[email protected]/Users/username/Desktop/my_file_name.jpg;type=image/jpg' \
4
-F 'fileName=my_file_name.jpg'
5
-F 'extensions="[
6
{
7
\"name\": \"remove-bg\",
8
\"options\": {
9
\"add_shadow\": true,
10
\"bg_colour\": \"green\"
11
}
12
},
13
{
14
\"name\": \"google-auto-tagging\",
15
\"minConfidence\": 55,
16
\"maxTags\": 15
17
}
18
]"'
Copied!
1
var ImageKit = require("imagekit");
2
var fs = require('fs');
3
​
4
var imagekit = new ImageKit({
5
publicKey : "your_public_key",
6
privateKey : "your_private_key",
7
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
8
});
9
​
10
fs.readFile('image.jpg', function(err, data) {
11
if (err) throw err; // Fail if the file can't be read.
12
imagekit.upload({
13
file : data, //required
14
fileName : "my_file_name.jpg", //required
15
extensions: '[
16
{
17
"name": "remove-bg",
18
"options": {
19
"add_shadow": true,
20
"bg_colour": "green"
21
}
22
},
23
{
24
"name": "google-auto-tagging",
25
"maxTags": 5,
26
"minConfidence": 95
27
}
28
]'
29
}, function(error, result) {
30
if(error) console.log(error);
31
else console.log(result);
32
});
33
});
Copied!
Last modified 1mo ago