Primeng: When using custom file uploads, selected file does not clear

Created on 22 Sep 2017  路  6Comments  路  Source: primefaces/primeng

When using uploadHandler to implement custom upload, the selected file is not cleared. For example, I select the first file to upload, the file is succesfully added to my array. When I click the upload button again, I do not get the option to select a new file. Instead, the previous file I selected is added to the array again.

Most helpful comment

@brianjly Hello,

Why did you think that incorrect behavior? If you want upload new files - push "cancel" button to clear array of files after uploading.
Or, as an example, you can trigger that programmatically, like this

<p-fileUpload #form name="myfile[]" customUpload="true" (uploadHandler)="myUploader($event, form)"></p-fileUpload>

Where custom uploader looks like

myUploader(event, form){
    for(let file of event.files) {
        this.uploadedFiles.push(file);
    }
    form.clear();
}

All 6 comments

@brianjly Hello,

Why did you think that incorrect behavior? If you want upload new files - push "cancel" button to clear array of files after uploading.
Or, as an example, you can trigger that programmatically, like this

<p-fileUpload #form name="myfile[]" customUpload="true" (uploadHandler)="myUploader($event, form)"></p-fileUpload>

Where custom uploader looks like

myUploader(event, form){
    for(let file of event.files) {
        this.uploadedFiles.push(file);
    }
    form.clear();
}

@Sumragen thank you so much, just what I was looking for. closing the issue now

@Sumragen thank you :)

Hi,
When i wrote
myUploader(event, form){
console.log(form , "my file form")
for(let file of event.files) {
this.uploadedFiles.push(file);
}
form.clear();
}

then it is printing "undefined" at console
please suggest me i want to also clear selected file dynamically without clicking on cut button
when it has been uploaded

@himanshubudhlakoti
I think you just forgot to use #form

<p-fileUpload #form name="myfile[]" customUpload="true" (uploadHandler)="myUploader($event, form)"></p-fileUpload>

Hello there ...

Another thing I have noticed is that the "choose" button is disabled upon an error or wathever happens after trying to upload. How can I re-enable this button after trying/successfully uploading a file?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

just-paja picture just-paja  路  3Comments

philly-vanilly picture philly-vanilly  路  3Comments

gatapia picture gatapia  路  3Comments

markgoho picture markgoho  路  3Comments

garethlewis picture garethlewis  路  3Comments