2017-12-02 4 views
0

Heyy peeps, angular2에서 ngx-uploader을 사용하고 있습니다. 응답에서 나는 백엔드에서 생성 된 파일 이름을 보내고 있습니다. 응답은 파일이 완전히 업로드 될 때만 전송됩니다. 내가 그것을 추적/듣기 어떻게,EventEmitters 업로드 진행 상황을 추적하는 방법? 가치 변화?

files: UploadFile[]; 
    uploadInput: EventEmitter<UploadInput>; 

     startUpload(): void { 
     const event: UploadInput = { 
      type: 'uploadFile', 
      url: 'http://localhost:3030/upload/quality-docs', 
      method: 'POST', 
      file: this.files[this.files.length - 1], 
     }; 


     this.uploadInput.emit(event); 
     } 

event.file의의 내부 진행의 백분율 값입니다 : 그래서 내가 어떻게는 다음과 같습니다 이벤트 이미 터에 의해 이루어집니다 업로드 과정을 확인할 수 있습니다. 그래서 그것의 100, 뭔가를 할 (응답의 이름 가치를 얻을)?

답변

0

을 내가 워드 프로세서 '추가 정보'에서이 ...을 할 수있는 올바른 방법을 발견 잠시 후이 onUploadOutput (output : UploadOutput)이라는 void 메소드 : void {}는 다음과 같이 보이는 if 문을 추가해야합니다.

else if(output.type === 'done') { whatever u wanna do} 
0

I이 가장 또는 오른쪽 방법이 아니다 알아,하지만 난 그것을 작동하게하는 방법이 있습니다 :

startUpload(): void { 
    this.uploaded = false; 
    const event: UploadInput = { 
     type: 'uploadFile', 
     url: 'http://localhost:3030/upload/quality-docs', 
     method: 'POST', 
     file: this.files[this.files.length - 1], 
    }; 

    this.uploadInput.emit(event); 
    this.repeat(event); 
    } 

    repeat(event) { 
    setTimeout(() => { 
     this.fileName = event.file.response.filename; 
     if (this.fileName == '' || this.fileName == undefined) { 
     this.repeat(event); 
     } 
     this.uploaded = true; 
    }, 200) 
    } 
관련 문제