If you are hiding the uploadbutton, you need another way to capture the files that are selected. one way to do that is to use onSelect
to store the files in an array that can be submitted with a form. Here is an example:
<p-fileUpload name="demo[]" #fileInput (onSelect)="onSelect($event)" [showUploadButton]="false" customUpload="true"></p-fileUpload>
And in the controller:
import { FormArray, FormControl, FormGroup, FormBuilder, Validators} from '@angular/forms';
private myFormFilesToUpload: FormArray;
constructor(private _fb: FormBuilder) {}
this.myForm = this._fb.group({
//...other form controls
filesToUpload: this._fb.array([])
});
this.myFormFilesToUpload = this.myForm.get('filesToUpload') as FormArray;
onSelect(event) {
if (event.files && event.files.length > 0) {
this.myForm.markAsDirty();
this.myFormFilesToUpload.push(this._fb.group({
fieldName: 'my_images',
files: this._fb.array(Array.from(event.files))
}));
}
}
Then the files should get sent went you submit the form.
[showUploadButton]="false"
so the upload handler is never triggered. I have used theonSelect
event to handle custom upload before, but it depends on what your exact requirements are. – mahi-manauto="true"
to start the upload as soon as a file is selected – mahi-manonSelect
which may help – mahi-man