-
Notifications
You must be signed in to change notification settings - Fork 165
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
Feature suggestion: ability to cancel the upload process #27
Comments
I'm not sure what you mean about this being an event, but I agree we need to be able to abort the upload process. |
I meant that maybe some logic could decide the file upload should be canceled for some reason. |
I see this working a few ways:
Right now, I'm having to use closure and |
I implemented something similar in my application-logic, piping to form
.on('part', function (fileStream) {
//discard if wrong imageType
if (allowedImageTypes.indexOf(req.params.imageType) === -1) {
fileStream.pipe(new BlackHoleStream());
return;
}
//save if everything worked fine
saveFile(...)
}); It might make extend |
I'm interested in this as well. Currently doing the form.on('part', function (part) {
if (!part.filename || /\.(gif|jpe?g|png)$/i.test(part.filename)) {
return part.pipe(fs.createWriteStream('/dev/null'));
}
}); |
@Starefossen your example shows that you want to be able to ignore certain parts. That seems like a desirable feature to me. We could also add that to the file hook so people could (if they acted sync on the event) prevent the temporary file from even being written. |
I think, a cancel method is very fundamental for this library. Is there any news on this? Thanks. |
This would be a great a useful feature! +1 👍 |
@Starefossen @meaku I have been trying to cancel the streams using both ways which you suggested and this seems to not work as I expect? What I am finding is that the stream seems to timeout before any response is sent to the client. I have tried to many ways like |
To clarify, none of the examples shown here actually cancel parsing of the request, they just toss the bits to Further, I found that simply calling Regardless, the black hole piping and my What is being suggested here is a way to stop parsing of the rest of the form due to an logic error during earlier parsing of the form. There is still no supported way to do this, and the user must jump through hoops to handle these cases. I still stand by my original suggestions for supporting this. |
Here is a solution that works for me.
|
Provide an event (i.e: 'cancel') in order that when emitted the upload process were canceled.
The text was updated successfully, but these errors were encountered: