Subscribe on upload file #366

Open
opened 2016-08-24 16:08:55 +00:00 by askurdjel · 3 comments
askurdjel commented 2016-08-24 16:08:55 +00:00 (Migrated from github.com)

Hi,

Is there any way that I can subscribe on upload method when is upload finished?

Thank you

Hi, Is there any way that I can subscribe on upload method when is upload finished? Thank you
IpaliboWhyte commented 2016-09-06 06:05:12 +00:00 (Migrated from github.com)

@askurdjel I sort of achieved this by simply overriding the onComplete property of the file-item class (file-item.class)

Here's a quick example:

this.uploader.queue[0].upload()
this.uploader.queue[0].onComplete = (response:string, status:number, headers:any)=> {
   console.log(response, status);
}

Hope this helps!

@askurdjel I sort of achieved this by simply overriding the `onComplete` property of the file-item class (file-item.class) Here's a quick example: ``` this.uploader.queue[0].upload() this.uploader.queue[0].onComplete = (response:string, status:number, headers:any)=> { console.log(response, status); } ``` Hope this helps!
VikramK commented 2016-12-07 16:29:32 +00:00 (Migrated from github.com)

This worked for me.

  var len = this.uploader.queue.length - 1;
    this.uploader.queue[len].onComplete = (response:string, status:number, headers:any)=> {
   console.log(response, status);
}
This worked for me. ``` var len = this.uploader.queue.length - 1; this.uploader.queue[len].onComplete = (response:string, status:number, headers:any)=> { console.log(response, status); } ```
jiggy1com commented 2016-12-21 06:25:57 +00:00 (Migrated from github.com)

I, too, wanted to subscribe to the response...

I found uploading a file is relatively easy to get going, but what happens if there's a duplicate? In my case, I want to notify the user rather than making the file unique or overwriting w/o the user's consent. I thought subscribe would be the way to go, but I found onCompleteItem to be useful.

I did something more along the lines of:

ngOnInit(){
  this.uploader.onCompleteItem = (fileItem, response, status, headers) => {
    if( JSON.parse(response).isDuplicate ){
      fileItem.showDuplicateButton = true; // fileItem reflects the item being uploaded in the queue
    }
  }
}

and inside my view (*ngFor="let item of uploader.queue") I can do something like

<button *ngIf="item.showDuplicateButton" (click)="forceOverwrite()">Force Overwrite</button>

This might be helpful to others.

I, too, wanted to subscribe to the response... I found uploading a file is relatively easy to get going, but what happens if there's a duplicate? In my case, I want to notify the user rather than making the file unique or overwriting w/o the user's consent. I thought subscribe would be the way to go, but I found **onCompleteItem** to be useful. I did something more along the lines of: ``` ngOnInit(){ this.uploader.onCompleteItem = (fileItem, response, status, headers) => { if( JSON.parse(response).isDuplicate ){ fileItem.showDuplicateButton = true; // fileItem reflects the item being uploaded in the queue } } } ``` and inside my view (*ngFor="let item of uploader.queue") I can do something like ``` <button *ngIf="item.showDuplicateButton" (click)="forceOverwrite()">Force Overwrite</button> ``` This might be helpful to others.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#366