(v2) How to get file information before completion of the upload?
aderchox opened this issue · 2 comments
Support plan
- which support plan is this issue covered by? (e.g. Community, Sponsor, or
Enterprise): Community - is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 16.13.1
- module (formidable) version: 2.0.1
- environment (e.g. node, browser, native, OS): node
- used with (i.e. popular names of modules):
- any other relevant information:
What problem are you trying to solve?
This is a 'question'. I want to clean up uploads that are aborted or have a size more than the max size specified. It seems that this has been fixed in a PR but it's been on v3 and doesn't work for me on v2, so I decided to do the deletion manually, however, if the upload is aborted, the file variable in the callback becomes an empty object making it impossible to find and delete the incomplete upload file... Is there a way to read file information before the upload is complete? Or if any other solutions to this? I don't want to change my module system just for this.
form.parse(req, (err, fields, file) => {
// file is an empty object on abort / maxSizeExceed
Do you have a new or modified API suggestion to solve the problem?
I recommend putting at least the upload's filename in the err
object passed to the callback so it can be used for the deletion.
form.parse(req, (err, fields, file) => {
// err can have some useful information about the incomplete upload
.
Oh it seems that there are events I can use. I'll try them and close this if they do what I need.
Yeah using events works. Closing.