0
I can make a file upload request through Postman, but when I make the Angular request, WARN is returned "Required Multipartfile Parameter 'file' is not present"
Follow my API feature made in Java with Spring boot.
@PostMapping
public ResponseEntity<Conteudo> publicaConteudo(@RequestParam("file") MultipartFile file) throws JsonParseException, JsonMappingException, IOException
{
/* ANYTHING */
return ResponseEntity.ok(new Conteudo());
}
And my Angular service. I’m using JWT, but I’m also trying to request using Httpclient.
upload(file: File, conteudo: Conteudo): Promise<any> {
let formData: FormData = new FormData();
formData.append('file', file, file.name);
/* USING JWT
return this.http.post(this.conteudoUrl, formData)
.toPromise()
.then(response => response.json());
*/
let h1 = new HttpHeaders().set('Authorization', 'Bearer ' +
localStorage.getItem('token'));
const req = new HttpRequest('POST',this.conteudoUrl, formData, {
headers: h1
});
return this.httpClient.request(req).toPromise();
}
I can make the request by Postman normally.
I tried many solutions I found, like creating a Multipartresolver Bean and etc, but no solution solved my problem and what I find most interesting is that it works normally on Postman.
Have you looked at the Networks tab as the request is going ?
– André Roggeri Campos
@Andréroggericampos I looked at it.. And I compared it to Postman’s. I couldn’t visualize anything that might be causing this problem. I’ll print it out and put it in the description.
– Igor Ramos
@Andréroggericampos I put the headers in the description
– Igor Ramos
Did you manage to solve? I have the same problem.
– Rodrigo Engelberg