Delete Files
The ExaDrive SDK provides functionality to delete files from your ExaDrive storage. This feature allows you to manage your storage space efficiently by removing unnecessary files.
Deleting a Single File
To delete a specific file from ExaDrive, use the deleteFile() method.
Syntax
exaDrive.deleteFile(directoryPath)fileName: A string representing the name of the file you want to delete.
Example
exaDrive.deleteFile('/myapp1/images/file1000.png')
.then((res) => {
console.log(res.data);
})
.catch((error) => {
console.error('Failed to delete file:', error);
});Response Structure
The method returns a promise that resolves with an object confirming the deletion of the file.
Response Fields
fileName: The name of the deleted file.
deleted: A boolean indicating whether the file was successfully deleted.
Deleting Multiple Files
To delete multiple files, you need to send separate requests for each file. Here's an example of how to delete multiple files:
Advanced Usage
Batch Deletion with Concurrency Control
For improved performance when deleting multiple files, you can implement a batch deletion function with concurrency control:
Deletion with Confirmation
Implement a confirmation step before deleting files to prevent accidental deletions:
Best Practices
Error Handling: Always include robust error handling to manage potential failures during the deletion process.
Confirmation: Implement a confirmation step for critical or irreversible deletions to prevent accidental data loss.
Logging: Maintain logs of deletion operations for auditing and troubleshooting purposes.
Batch Processing: When deleting multiple files, use batch processing with concurrency control to optimize performance and respect API rate limits.
Cleanup Routines: Implement regular cleanup routines to automatically delete unnecessary or temporary files:
Soft Delete: Consider implementing a "soft delete" feature in your application logic, where files are marked as deleted but not immediately removed from storage. This can provide a safety net for accidental deletions.
By following these practices and utilizing the deletion capabilities of the ExaDrive SDK, you can effectively manage your file storage and maintain an organized ExaDrive environment.
Last updated