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
Bulk file delete API

https://api.imagekit.io/v1/files/batch/deleteByFileIds
Deletes multiple files from the media library.
Request
Response
Request
Headers
Authorization
required
string
base64 encoding of your_private_api_key: Note the colon in the end.
Form Data Parameters
fileIds
required
array
Each value should be a unique fileId of the uploaded file. fileId is returned in list files API and upload API
Response
200: OK
On success, a 200 is returned along with the array of fileIds which are successfully deleted.
{
"successfullyDeletedFileIds": [
"5e1c13d0c55ec3437c451406",
...
]
}
404: Not Found
If any of the fileId is not found in your media library then a 404 response is returned and no file is deleted. The whole operation fails.
{
"message": "The requested file(s) does not exist.",
"help": "For support kindly contact us at support@imagekit.io .",
"missingFileIds": [
"5e21880d5efe355febd4bccd",
"5e1c13c1c55ec3437c451403"
]
}

Response structure and status code

In case of 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
cURL
# 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" : ["5e1c2079c55ec3437c451b6d"]
}
'
Node.js
imagekit.bulkDeleteFiles(["fileId1","fileId2"])
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
Python
imagekit.bulk_file_delete(["file_id1", "file_id2"])
PHP
$imageKit->bulkFileDeleteByIds(array(
"fileIds" => array("file_id_1", "file_id_2")
));
Java
List<String> fileIds=new ArrayList<>();
fileIds.add("fileId1");
fileIds.add("fileId2");
ResultFileDelete result=ImageKit.getInstance().bulkDeleteFiles(fileIds);
Ruby
imagekitio = ImageKit::ImageKitClient.new("your_private_key", "your_public_key", "your_url_endpoint")
bulk_ids = Array["fileId1","fileId2"]
imagekitio.bulk_file_delete(bulk_ids)