The callback function could not be executed.
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
Server Environment: `Windows10 WSL Ubuntu 20.04.2 LTS`
Client Environment: `Windows10 C# Program`
An error was encountered while changing communication from `HTTP` to `HTTPS`
The callback function cannot be entered.
```typescript
const upload = multer({ dest: config.ROOT + '/uploads/' });
router.post('/upload', cpUpload, async function(req: express.Request, res: express.Response, next: express.NextFunction) {
console.log('1234');
res.end();
});
// express error handling
const errorHandler: ErrorRequestHandler = (err, req, res, next) => {
console.error(err.stack);
console.log('5678');
res.status(500).send('5678');
};
app.use(errorHandler);
```
"1234" is not output.
It doesn't produce any errors, nor does "5678" print.
But the file is uploaded.
However, the capacity is smaller than the original file.
**At this time, I want to notify the user that uploading is not possible due to a communication problem and then delete the abnormally uploaded file.**
It is probably because the client disconnects the communication quickly.
Changing the timeout on the client solves it, but I want to fix it on the server.
```typescript
const cpUpload = upload.fields(
[
{ name: 'map', maxCount: 1 }, { name: 'image', maxCount: 1 },
]
);
router.post('/upload', function(req: express.Request, res: express.Response, next: express.NextFunction) {
cpUpload(req, res, function (err) {
console.log('cpUpload start'); // Can't get in here.
if (err instanceof multer.MulterError) {
// Can't get in here.
console.log('err1');
console.log(err);
}
else if (err) {
// Can't get in here.
console.log('err2');
console.log(err);
}
// Can't get in here.
console.log(req.files);
console.log('1234');
res.end();
});
console.log('t', req.files); // null
});
```
req.files returns null and cannot be entered into the callback function of "cpUpload".
How can I delete the uploaded abnormal files at this time?
(The file name is a random hash.)
---
Tried several things...
I've found that it doesn't call the "Finish" event.
https://github.com/expressjs/multer/blob/63f487421baec6f20d6a0a38561698f80daa2cb6/lib/make-middleware.js#L171
I wonder why the client program has exited but the "Finish" event is not being called.
Contributor guide
Assessment
This issue has not been assessed yet.