0
I’m trying to get a file attached through a button. The problem is that the file arrives but is not setting, as shown in the images below, just below the images has the method and the html button.
docFile(event: any) {
let reader = new FileReader();
let size = event.target.files[0].size;
if (event.target.files && event.target.files.length > 0) {
let file = event.target.files[0];
if (size > 2097152) {
this.template.openModal()
} else {
reader.readAsDataURL(file);
reader.onload = (event: any) => {
this.imagemDoc = event.target.result;
console.log(size);
this.dadosPessoaisForm.get('documentos.arquivo').setValue({
id: this.arquivo.id,
nome: file.name,
tipo: file.type,
// dados: reader.result.split(',')[1]
})
};
}
}
}
<div class="input-group-addon" style="background-color: #ffffff">
<div class="upload-btn-wrapper">
<button type="file" class="fa fa-paperclip"></button>
<input type="file" class="btn btn-default" id="arquivo" accept='file/*' (change)="docFile($event)" #fileInput>
</div>
</div>
The console.log(size) was made in the function as requested in the comment and the result was this of the image below.
You can give a console. log to Event.target.files and see if the structure is correct ?
– Lucas Brogni
I just did and the result is in the last lines of my question.
– Fabiano Camargo