Delete file

You can programmatically delete uploaded files in the media library using delete file API.

If a file or specific transformation has been requested in the past, then the response is cached. Deleting a file does not purge the cache. You can purge the cache using purge API.

delete
Delete file API

https://api.imagekit.io/v1/files/:fileId
Deletes a file from the media library.
Request
Response
Request
Path Parameters
fileId
required
string
The unique fileId of the uploaded file. fileId is returned in list files API and upload API
Headers
Authorization
required
string
base64 encoding of your_private_api_key: Note the colon in the end.
Response
204: No Content

Response structure and status code

In case of an error, you will get an error code along with the error message. On success, you will receive a 204 status code with an empty body.

Examples

Here is the example request to understand the API usage.

cURL
Node.js
Python
PHP
Java
Ruby
cURL
# The unique fileId of the uploaded file. fileId is returned in response of list files API and upload API.
curl -X DELETE "https://api.imagekit.io/v1/files/fileId" \
-u your_private_key:
Node.js
var ImageKit = require("imagekit");
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
imagekit.deleteFile("file_id", function(error, result) {
if(error) console.log(error);
else console.log(result);
});
Python
from imagekitio import ImageKit
imagekit = ImageKit(
private_key='your_public_api_key',
public_key='your_private_api_key',
url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
)
delete = imagekit.delete_file("file_id")
print("Delete File-", delete)
PHP
use ImageKit\ImageKit;
$public_key = "your_public_api_key";
$your_private_key = "your_private_api_key";
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
$imageKit = new ImageKit(
$public_key,
$your_private_key,
$url_end_point
);
$deleteFile = $imageKit->deleteFile("file_id");
echo("Delete file : " . json_encode($deleteFile));
Java
Result result=ImageKit.getInstance().deleteFile("file_id");
Ruby
imagekitio = ImageKit::ImageKitClient.new("your_private_key", "your_public_key", "your_url_endpoint")
delete = imagekitio.delete_file("file_id")