How to Recover a Deleted Document in Alfresco
When working with Alfresco, a common issue arises when you need to recover a deleted document, but the original folder where the document resided has also been deleted. In such cases, attempting to restore the document from the trashcan results in an error. This article outlines the steps to resolve this issue and provides two potential solutions.
Scenario
Let's consider the following scenario: a document named "20231204 - Sample PDF.pdf" was created under the site site-01 in the folder fldr-01. Both the document and the folder were subsequently deleted. When trying to recover the document from the trashcan, the following error is encountered:
Solution 1: Restore the Original Folder
The first option is to restore the original folder where the document was located. Once the folder is restored, you can proceed to recover the document. This method works well if the folder and its contents are still needed.
Steps to Restore the Original Folder:
- Access the Trashcan: Navigate to the Alfresco trashcan where deleted items are stored.
- Locate the Folder: Find the deleted folder fldr-01 under the site site-01.
- Restore the Folder: Restore the folder fldr-01.
- Recover the Document: Once the folder is restored, find the document Check 20231204 - Sample PDF.pdf in the trashcan and restore it.
Solution 2: Use the API to Restore the Document to a New Folder
If you prefer not to restore the original folder, you can use the Alfresco REST API to restore the document to a new or different folder. This method provides flexibility to organize your content as needed.
Steps to Restore the Document to a New Folder:
- Create a New Folder: Create a new folder in the desired location within Alfresco. For example, you might create a new folder named fldr-02 under site-01.
- Get the Node ID of the New Folder: Use the Alfresco Node Browser or API to obtain the node ID of the newly created folder. In the screenshot below, it is 63c17a5f-b609-4f78-b09e-470179cfcc6d.
- Get the Node ID of the deleted file Node ID: 3bfa289e-ba5f-4aec-b43b-7585a6415369
- Restore the Document Using the API: Use the REST API to restore the document to the new folder by specifying the targetParentId (node ID of the new folder) and the assocType (cm:contains).
REST API Request:
API reference: Alfresco Content Services REST API ExplorerAssuming the node ID of the deleted document is 3bfa289e-ba5f-4aec-b43b-7585a6415369 and the node ID of the new folder is 63c17a5f-b609-4f78-b09e-470179cfcc6d, the API request would be as follows:
Conclusion
When a document is deleted in Alfresco and the original folder is missing, you have two options to recover the document. You can either restore the original folder first and then recover the document, or you can use the Alfresco REST API to restore the document to a new folder. By following the steps outlined above, you can effectively manage and recover your content in Alfresco.
Post a comment