Is possible to cancel an upload?
Hello. See the same question at March 14, but there are no answers. So, maybe somebody got same problem before, and know how to solve it?
This is not possible now. Service does not expose XMLHttpRequest instance. I think it can be part of passed UploadedFile structure. What do you think @jkuri? I'm happy to create pull request with this change.
I provided abortUpload method. Can anyone with write access approve and merge this?
In version 2.2.8 you can do it by UploadedFile class object using abortUpload() method.
Try this:
public beforeUpload(uploadingFile: UploadedFile): void {
this.uploadingFile = uploadingFile;
}
public onCancel() {
if (this.uploadingFile) {
this.uploadingFile.abortUpload();
}
}
hi @marekszczepansky. can you please add this to README?
OK, i'll try to find a proper place for it.
I'm trying to cancel an upload through this code:
this.uploadInput.emit({ type: 'cancelAll' });
but, apart emitting an event, it doesn't abort the XMLHttpRequest.
What's the issue about it?
EDIT: I've seen @marekszczepansky update but it's not visible in the ngx-uploader.class
i am also trying cancel, no efect @marekszczepansky fix is for 2.x.x branch im on 3.0.6
@lukwas314 I havn't done PR for 3.x version. Maybe this can cause that it works only in => 2.2.8 version. I've some spare time at work so I can test it on 3.x version.
I have my code workin' and cancel works like a charm.
No effect for me (3.1.1) my console.log : Object {type: "cancelled", file: Object} Object {type: "uploading", file: Object} Object {type: "uploading", file: Object} Object {type: "uploading", file: Object} Object {type: "done", file: Object}
we succeeded in aborting upload on 3.x using cancel event instead cancellAll and uploadFile instead uploadAll, but after cancel we cannot upload new files
@lukwas314, this should fix this. I also updated demo example and published 3.2.0 to npm. please let me know if it works for you.
@jkuri cancel and new files upload works in 3.2.0
hi marekszczepansky,
i have used this method in version 2.8.8
public beforeUpload(uploadingFile: UploadedFile): void { this.uploadingFile = uploadingFile; }
public onCancel() { if (this.uploadingFile) { this.uploadingFile.abortUpload(); } }
but it's throw error to not find abortUpload method
@anilkcspl IIRC this method is still in 2.x.x. source code: https://github.com/jkuri/ngx-uploader/blob/2.x.x/src/classes/uploaded-file.class.ts#L39 Please check your node_module for this sourceline.
I am using this:
const event: UploadInput = {
type: 'cancel' // also tried 'cancelAll'
};
this.uploadInput.emit(event);
But nothing happens... The upload is still going, until it finishes uploading. :( Shouldn't it be straight forward? Shouldn't emitting a 'cancelAll' input event simply cancel all current uploads?
Also, in the serviceEvent subscription, if I simply console log event.type, the cancel (or cancelAll) doesn't show up...
So, right now, if the user decides to cancel a 4GB video upload, the actual file still keeps uploading until it finishes (or the user refreshes or closes the page), taking up bandwidth.
ngx-uploader: 3.3.9
It's still happening on v6.0.1. Seems that uploadInput has no observer.