1
I have the following form:
<form [formGroup]="notifForm">
<div class="box-body">
<app-input errorMessage="Preencha a Descrição" [showTip]="false">
<label for="descricao">Título</label>
<input type="text" class="form-control" placeholder="Descrição" minlength="5" formControlName="descricao">
</app-input>
<app-input errorMessage="É obrigatório adicionar arquivo" [showTip]="false">
<label for="arquivo">Anexar arquivos</label>
<input type="file" formControlName="arquivo" multiple (change)="fileChangeEvent($event)">
</app-input>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary" [disabled]="notifForm.invalid" (click)="enviar()">Submit</button>
</div>
</form>
I’m sending it like this:
this.notificationService.save( this.notifForm.value )
.subscribe( r => {
message.message = 'Cadastrado com sucesso!'
message.status = true
this.notificationService.notify( message )
this.router.navigate(['/notificacao/notificacao'])
}, err => {
message.message = 'Houve problema ao tentar salvar!'
message.status = false
console.error('Erro', err.message);
this.notificationService.notify( message )
})
No Node I’m getting the data like this:
notificacaoRouter.post( `${prefix}/save`, async (req: any, res, next)=>{
console.log(req.body);
next()
})
The result is coming out like this:
{ descricao: 'sdfdsfd',
detalhe: 'fdfdfd',
arquivo: 'C:\\fakepath\\linda.jpg'
}
I send two files and only get one file.
I would like to read them all and would like to know how to copy this file to a specific folder
I set it up here
import * as multipart from 'connect-multiparty'
const multipartMiddleware = multipart({uploadDir: './public'})
But I don’t know how to use it...
I saw many tutorials that only teach to upload a single file and not form containing text.