-
-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel/abort upload process (Feature request) #471
Comments
Absolutely. That's a thing that i was thinking for a long time and received few issues related to that. Such as https://github.com/tunnckoCore/koa-better-body/issues/65 - package that is my main source for finding bugs (and used heavily for years by many) and related things to Formidable. We had discussions for a lot of the things. The linked issue is for file size limitting, but if there was way for canceling it wouldn't exist probably. So from here follows... throw from the event handler? - may work for now, until we implement abort/cancel. edit: oh, this comment was probably better for the #456 and #457, i'll link it there. |
Any news? |
@hassan-jahan, unfortunately, don't think so. |
I am on it |
any news @GrosSacASac ? don't want to be forced to switch libs tbh |
@noonii, doesn't that
Work? Throw from the handler (attaching any useful metadata to the error) then from the |
I've tried to force quit using I know where it's uploading and I can customize The only time I've seen the parser successfully destroy uploading is here . I've been adding guards in EDIT: I ended up overriding EDIT2: If |
@noonii thanks for the feedback. That's the reason of
Interesting. I have some thoughts. Can you bring some code (your |
This implementation guards against specified files, but will upload otherwise. |
@noonii Thanks. Okay, another approach... what about putting it on Okay. This one? // in future we should just pass the whole `part` here
// instead of `part.name`
form.on('fileBegin', (partName, file) => {
if (file.name) {
// Validate allowed file ext
if (!isSupportedFileExt(part.filename)) { // video or caption file
// and in the end (before emitting/throwing)
file.open = () => {}
file.write = () => {}
file.end = () => {}
this.emit('error', new Error(`File extension for [ ${part.filename} ] is not supported.`));
return;
}
// Guard multiple files
// Guard file size
// and in the end (before emitting/throwing)
file.open = () => {}
file.write = () => {}
file.end = () => {}
}
}) The cool thing of references, haha... edit: |
Oooor... again with form.on('file', (partName, file) => {
// when needed
file._writeStream.destroy();
this.emit('error')
// or
// file.emit('error')
}) but I guess it will make a file again... not sure. |
True. But we'll figure it out : ) Feedback and trying is the key ;p I'd love to be in v2. That's probably why I don't releasing it yet. There are such very important & significant problems. |
While the file event would be an alternative, we would overwrite the guards against |
Yup. This |
Okay, I think the easiest and cleanest approach for now is the "file methods Other future approach could Validators API, like |
Try the branch https://github.com/node-formidable/formidable/tree/filter-upload let customError = false;
const form = formidable({
filter: function ({name, originalFilename, mimetype}) {
return !customError;
}
});
form.on("field", function (name, value) {
// Reject if a form field value is empty
if (_.isEmpty(value)) {
customError = true
return;
}
});
form.parse(req, (err, fields, files) => {
if (err || customError) {
res.sendStatus(400);
return;
}
// ...
}); |
When the lib receives files and fields, it starts to receive (upload) files in any case.
For example, I check form fields for emptiness, and reject the request. But it still accepts the files and stores them, and I can't prevent it.
So in this example, if the received form consists of an empty field, and a file, its not possible to stop the file from being accepted (correct me if I've mistaken).
The text was updated successfully, but these errors were encountered: