To check which files or images were deleted in Redactor, there is the Storage service.
Storage helps you maintain control over the files and images uploaded to your servers through Redactor. Use storage if you'd like to always only have current files saved on server, and make cleanup and removal of unused files and images a breeze.
There are three components of the Storage service.
With every upload, every file and image along with URL and name should be assigned an id. This id will serve as a unique identification of this particular uploaded file within your application.
Here's how to assign an id attribute:
data-image="%id%"
- for image uploadsdata-file="%id%"
- for file uploadsWhen you've got some Redactor uploading going on in your system, and your customer upload, delete, undo and redo uploads and deletions of their files and images, storage.getChanges
helps you keep track of the files in use. Here's how it works:
storage.getChanges
method, for example, through an autosave callback. This method will return an object of all files and images currently in Redactor).Each element in the storage.getChanges
list has a status: existing and currently used in Redactor files and images are true
, and those deleted by the user are false
. Now you know which files can be safely deleted from server (hint: those with false
status) and you can delete these files using their ids.
Here's an example of storage.changes method in use:
var changes = $R('#content', 'storage.getChanges');
for (var key in changes)
{
if (changes[key].status === false) // element was deleted
else // element is still in the content
}
Here's an example of an object that is returned by getChanges:
"some-id: {
id: "some-id", // an id of a file. This id had been set during upload.
node: img, // or 'a' DOM node of element
status: true, // or false if element is deleted
type: "image" // or file
}