Links
Comment on page

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
https://api.imagekit.io
/v1/files/:fileId
Delete file API

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
Go
.Net
# 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/file_id" \
-u your_private_key:
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);
});
from imagekitio import ImageKit
imagekit = ImageKit(
public_key='your_public_api_key',
private_key='your_private_api_key',
url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
)
delete = imagekit.delete_file(file_id="file_id")
print("Delete File-", delete)
# Raw Response
print(delete.response_metadata.raw)
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
);
$fileId = 'file_id';
$deleteFile = $imageKit->deleteFile($fileId);
echo("Delete file : " . json_encode($deleteFile));
Result result=ImageKit.getInstance().deleteFile("file_id");
imagekitio = ImageKitIo::Client.new("your_private_key", "your_public_key", "your_url_endpoint")
delete = imagekitio.delete_file(file_id: "file_id")
ik, err := imagekit.New()
resp, err := ik.Media.DeleteFile(ctx, "file_id")
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
ResultDelete res2 = imagekit.DeleteFile("file_Id");