Learn how to delete media files via the Media API.
Media files are any files that are uploaded to the Staffbase platform. This can be user avatar images, header images, or any images in the My Files or My File Manager. In this article, you will learn how to delete a media file using the Media API.
There can be different use cases why you want to delete media files. For instance, your company’s logo may have changed, and you may want to delete the current images or delete images that were reported as offensive or not falling within your corporate communication guidelines.
mediumID
using the URL.To delete a media file, do the following:
mediumID
of the media fileIt is also possible to obtain a list of media files and their respective mediumID
by sending a GET
request to /media
endpoint. However, this approach has a limitation as the GET
request will retrieve a list of all media files along with their mediumID
s, making it difficult to determine the specific mediumID
of the file that needs to be deleted.
mediumID
. https://example.staffbase.com/api/media/secure/external/v2/image/upload/w_554,h_641/c_limit,w_1000,h_1000/66295b72c06bb61d04780ba3.png
, copy 66295b72c06bb61d04780ba3
at the end of the URL.You have copied the mediumID
.
Make a DELETE
request to the endpoint /media/{mediumID}
for each media file that you want to delete.
You get a 204 response that the media file is deleted.
Even after completing the request to delete the file successfully, it may take several minutes for the file to be removed from the cache. Therefore, if a user attempts to access the file immediately after deletion, it may still be available.
To bulk trigger the deletion of multiple media files, add a function to loop through multiple mediumID
s to perform your request.