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.
{"successfullyDeletedFileIds": ["5e1c13d0c55ec3437c451406",... ],"errors": [ { fileId:"3e21880d5efe355febd4bccx", error:"Error in deleting tags" }, { fileId:"5fc1c55efe355febddcda3d1", error:"Error in deleting tags" } ]}
{"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 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.
# Array of the unique fileId of the uploaded files. fileId is returned in response of list files API and upload API.curl-XPOST"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"]}'
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 Responseprint(bulk_file_delete.response_metadata.raw)# list successfully deleted file idsprint(bulk_file_delete.successfully_deleted_file_ids)# print the first file's idprint(bulk_file_delete.successfully_deleted_file_ids[0])