ngx-uploader icon indicating copy to clipboard operation
ngx-uploader copied to clipboard

Is possible to cancel an upload?

Open PavelRadev opened this issue 8 years ago • 16 comments

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?

PavelRadev avatar Jan 24 '17 22:01 PavelRadev

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.

marekszczepansky avatar Feb 24 '17 14:02 marekszczepansky

I provided abortUpload method. Can anyone with write access approve and merge this?

marekszczepansky avatar Mar 01 '17 13:03 marekszczepansky

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();
	}
}

marekszczepansky avatar Apr 12 '17 14:04 marekszczepansky

hi @marekszczepansky. can you please add this to README?

jkuri avatar Apr 12 '17 17:04 jkuri

OK, i'll try to find a proper place for it.

marekszczepansky avatar Apr 13 '17 15:04 marekszczepansky

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

davidere avatar May 18 '17 14:05 davidere

i am also trying cancel, no efect @marekszczepansky fix is for 2.x.x branch im on 3.0.6

lukwas314 avatar Jun 09 '17 08:06 lukwas314

@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.

marekszczepansky avatar Jun 16 '17 20:06 marekszczepansky

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}

ljacques avatar Jun 22 '17 09:06 ljacques

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 avatar Jun 30 '17 11:06 lukwas314

@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 avatar Jun 30 '17 12:06 jkuri

@jkuri cancel and new files upload works in 3.2.0

lukwas314 avatar Jun 30 '17 13:06 lukwas314

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 avatar Jul 21 '17 11:07 anilkcspl

@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.

marekszczepansky avatar Aug 19 '17 20:08 marekszczepansky

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

NgxDev avatar Aug 23 '17 07:08 NgxDev

It's still happening on v6.0.1. Seems that uploadInput has no observer.

dfliess avatar Jul 27 '18 17:07 dfliess