简体   繁体   English

如何使用angular2在p-fileUpload成功消息后清除上传的文件

[英]How to clear the uploaded files after success message in p-fileUpload using angular2

i am using p-fileUpload plugin from primeng, after uploading the files, i still can see the files which i have uploaded after success message.我正在使用primeng的p-fileUpload插件,上传文件后,我仍然可以看到成功消息后我上传的文件。 Can anyone help me how to hide these files, after success message.任何人都可以在成功消息后帮助我如何隐藏这些文件。

HTML: HTML:

<p-fileUpload #form name="photo" type="file" customUpload="true" (uploadHandler)="fileChangeEvent($event, form)" multiple="multiple"></p-fileUpload>

TS: TS:

  fileChangeEvent(fileInput: any, form) {
    if (
      fileInput.files.some(f => this._validFileExtensions.indexOf(f.type) != -1)
    ) {
      this.showError("Invalid file Added");
    } else {
      this.upload(fileInput.files, form);
    }
  }

I need to clear the files when this functionality is called,调用此功能时,我需要清除文件,

if (this.progressStatus === 'done') {
  this.progressValue = 100;
  this.progress = false;
  clearInterval(interval);
  return ;
}

I had same problem with p-fileUpload component.我对 p-fileUpload 组件有同样的问题。 This is how i managed to delete files after upload with uploadHandler.这就是我在使用 uploadHandler 上传后设法删除文件的方法。 On html i added [files]="myfiles"在 html 上我添加了 [files]="myfiles"

 <p-fileUpload [files]="myfiles" customUpload="true (uploadHandler)="myUploader($event)" maxFileSize="6000000">

and then in ts然后在 ts

      myfiles: any = [];
      myUploader(event) {
        if (this.myfiles != undefined && this.myfiles.length > 0) {

          this.myfiles.forEach(element => {
            var re = /(?:\.([^.]+))?$/;
            let file = element;
            var that = this;
            var newFile = {
              FilePath: "",
              FileName: element['name'],
              Extension: re.exec(element['name'])[1]
            };
            this.getBase64(file).then(
              data => {
                newFile['MIME'] = file.type;
                newFile['FileSize'] = file.size;
                newFile['FileContent'] = (<string>data).split(',')[1].replace(String.fromCharCode(92), String.fromCharCode(92, 92));
                that.saveFile(newFile);
              }

            );
          });

          this.myfiles = [];
        }
      }

 getBase64(file) {
    return new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => resolve(reader.result);
      reader.onerror = error => reject(error);
    });
  }

Hope it helps希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM