0

i have simple file upload implemented on my angular 4 app, everything works well, but i have one issue that i'm not sure how to fix, so when i finish uploading first item, onSuccessItem callback triggers and i do some logic there, BUT when i upload another file that same callback won't trigger. My question is how to trigger onSuccessItem callback every time when file is uploaded, i don't want to refresh page. My code looks like this. I'm using this plugin https://github.com/valor-software/ng2-file-upload

import { Component } from '@angular/core';
import {FileUploader, FileItem, ParsedResponseHeaders} from "ng2-file-upload";

@Component({
    selector: 'upload-file',
    template: `
    <input type="file" ng2FileSelect [uploader]="uploader">    
    `,
})
export class UploadFileComponent {
    uploader:FileUploader;
    ngOnInit(): void {
        this.uploader = new FileUploader({
            url: 'http://url.to/upload',
            headers: [{name:'Accept', value:'application/json'}],
            autoUpload: true,
        });
        this.uploader.onErrorItem = (item, response, status, headers) => this.onErrorItem(item, response, status, headers);
        this.uploader.onSuccessItem = (item, response, status, headers) => this.onSuccessItem(item, response, status, headers);
    }

    onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
        //this gets triggered only once when first file is uploaded
    }

    onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
        let error = JSON.parse(response); //error server response
    }
}
Sahbaz
  • 1,242
  • 4
  • 17
  • 39

1 Answers1

1

Seems like a bug in the library.

Reported here : https://github.com/valor-software/ng2-file-upload/issues/872 by you

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Well that is true i reported it, but it's not confirmed that is bug. So i guess maybe im doing something wrong. – Sahbaz Aug 29 '17 at 15:40