file is not removed if upload is canceled
See original GitHub issueConsider this minimal working example (Multer v1.1.0 on Windows 7, OS X 10.11 and Ubuntu 14.04 with node v4.2.1):
var express = require('express')
var multer = require('multer')
var upload = multer({ dest: 'uploads/' })
var app = express();
app.post("/upload", upload.single("file"), function(req, res, next){
res.end("uploaded to: " + req.file.filename);
});
app.listen(80);
and the following test script
# create large test file
$ dd if=/dev/urandom bs=2G count=1 of=upload
# upload
$ curl -F "file=@upload" http://localhost/upload
# upload again, but cancel before upload is finished
timeout -s SIGKILL 2s curl -F "file=@upload" http://localhost/upload
Expected behavior: Only the first file is persisted, the second is removed after the upload got canceled.
Actual behaviour: Both files are stored in the uploads folder
Issue Analytics
- State:
- Created 8 years ago
- Reactions:6
- Comments:40 (1 by maintainers)
Top Results From Across the Web
Multer file is not removed if upload is canceled - Stack Overflow
Is there Any Function in Multer To Remove uploaded part of the File from the server if The Request gets Cancelled.
Read more >Cancel button does not delete the uploaded file after ... - Telerik
Hi Konstantinos, The Cancel button is used to cancel the current upload session. After the file has been uploaded, the session is complete...
Read more >Delete uploaded data if browser closed or cancel upload
It seems that if browser is closed, some of the data is already stored locally. And if you meet error, The program has...
Read more >How to detect when cancel is clicked on file input using ...
javascript · When the user uploads any file, the length of the files is found using theFile.value.length property. · When the user does...
Read more >431098 - Impossible to clear file upload controls (fields)
In FF2 days, I'd simply select the file path in the text box, and delete it. ... I.e. it cancels the whole action...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is my approach worked for me
I thought perhaps the error handling code from the README was the solution, but it seems the callback is not called if the request is aborted.
This post might help.
EDIT : This is what I came up with :
We know when if the upload gets canceled. However the partially uploaded file still can’t be deleted, since only multer knows its name ; deleting the most recent file could be a temporary solution.