Links
Comment on page

Delete files (bulk)

You can programmatically delete multiple files uploaded in the media library using bulk file delete 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.
post
https://api.imagekit.io
/v1/files/batch/deleteByFileIds
Bulk file delete 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 200 status code with JSON encoded response containing information about successfully deleted fileIds.

Examples

Here is the example request to understand the API usage.
cURL
Node.js
Python
PHP
Java
Ruby
Go
.Net
# Array of the unique fileId of the uploaded files. fileId is returned in response of list files API and upload API.
curl -X POST "https://api.imagekit.io/v1/files/batch/deleteByFileIds" \
-H 'Content-Type: application/json' \
-u your_private_key: -d '
{
"fileIds" : ["file_id_1", "file_id_2"]
}
'
imagekit.bulkDeleteFiles(["file_id_1","file_id_2"])
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
bulk_file_delete = imagekit.bulk_file_delete(file_ids=["file_id_1", "file_id_2"])
print("Bulk file delete-", bulk_file_delete, end="\n\n")
# Raw Response
print(bulk_file_delete.response_metadata.raw)
# list successfully deleted file ids
print(bulk_file_delete.successfully_deleted_file_ids)
# print the first file's id
print(bulk_file_delete.successfully_deleted_file_ids[0])
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
);
$fileIds = ["file_id_1", "file_id_2"];
$deleteBulkFiles = $imageKit->bulkDeleteFiles($fileIds);
echo("Delete Bulk files : " . json_encode($deleteBulkFiles));
List<String> fileIds=new ArrayList<>();
fileIds.add("file_id_1");
fileIds.add("file_id_2");
ResultFileDelete result=ImageKit.getInstance().bulkDeleteFiles(fileIds);
imagekitio = ImageKitIo::Client.new("your_private_key", "your_public_key", "your_url_endpoint")
bulk_ids = Array["file_id_1","file_id_2"]
imagekitio.delete_bulk_files(file_ids: bulk_ids)
resp, err := ik.Media.DeleteBulkFiles(ctx, media.FileIdsParam{
FileIds: []string{"file_id_1", "file_id_2"},
)
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
List<string> ob3 = newList<string>();
ob3.Add("fileId_1");
ob3.Add("fileId_2");
ResultFileDelete resultFileDelete = imagekit.BulkDeleteFiles(ob3);