Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng2-file-upload single upload override file upload

I do the demo base on this tutorial: https://github.com/valor-software/ng2-file-upload. I want to single file upload but without remove file button. By adding the File A, after that I add the File B. File A will be replaced by file B. here is my uploader:

 this.uploader = new FileUploader(
      {
        url: this.baseURL,
        allowedFileType: ["xls"],
        maxFileSize: 5,
        queueLimit: 1
      });

Please advice me

like image 316
Phạm Quốc Bảo Avatar asked Sep 02 '25 16:09

Phạm Quốc Bảo


1 Answers

As Arun Muthiyarkath suggested, you can use the onAfterAddingFile, but the shorter code would be:

  ngOnInit() {
    this.uploader.onAfterAddingFile = (fileItem: FileItem) => {
      if (this.uploader.queue.length > 1) {
        this.uploader.removeFromQueue(this.uploader.queue[0]);
      }
    };
  }

Source: https://github.com/valor-software/ng2-file-upload/issues/703

like image 151
Rijaz Ali Avatar answered Sep 04 '25 06:09

Rijaz Ali