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.
your_private_api_key:
Note the colon in the end.fileId
is returned in list files API and upload API200
is returned along with the array of fileIds
which are successfully deleted.{"successfullyDeletedFileIds": ["5e1c13d0c55ec3437c451406",...]}
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"]}
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
.
Here is the example request to understand the API usage.
# 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"]}'
imagekit.bulkDeleteFiles(["fileId1","fileId2"]).then(response => {console.log(response);}).catch(error => {console.log(error);});
imagekit.bulk_file_delete(["file_id1", "file_id2"])
$imageKit->bulkFileDeleteByIds(array("fileIds" => array("file_id_1", "file_id_2")));
List<String> fileIds=new ArrayList<>();fileIds.add("fileId1");fileIds.add("fileId2");ResultFileDelete result=ImageKit.getInstance().bulkDeleteFiles(fileIds);
imagekitio = ImageKit::ImageKitClient.new("your_private_key", "your_public_key", "your_url_endpoint")bulk_ids = Array["fileId1","fileId2"]imagekitio.bulk_file_delete(bulk_ids)