Fix cleaning up temporary files on client abort. #438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have an alternative solution to fix #259.
The advantage to this PR is that the user of the multer library will get a proper error object indicating the reason for the failure ("client aborted"). An advantageous side-effect of this PR is that it removes a dependency. I have also added a test to simulate the situation.
A downside of this PR is that it introduces breaking API changes (another error code that introduces behavioral changes) and I had to change the Storage API so that the Disk Storage can know which file to remove when an unfinished file is canceled.
If desired, I could add a check to see if the callback to
_handleFile()still receives the secondinfoparameter and if it does it could still extend thefileobject with it. That way we would need to bring back thextenddependency, but it would make it even easier for any users to upgrade to the new version, as any existing custom Storage implementations should remain compatible.