Required MultipartFile parameter 'file' is not present when I make a request for Angular 4

0

I can make a request to upload a file through Postman, but when I make the request of the Angular, the WARN "Required MultipartFile parameter 'file' is not present"

Here's my Java API feature with Spring boot.

@PostMapping
public ResponseEntity<Conteudo> publicaConteudo(@RequestParam("file") MultipartFile file) throws JsonParseException, JsonMappingException, IOException 
{
   /* ANYTHING */
   return ResponseEntity.ok(new Conteudo());
}

And my service in Angular. I'm using JWT, but I'm also trying to make the 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 do the requisition by postman normally.

ItriedmanysolutionsthatIfound,likecreatingaBeanMultipartResolverandetc.,butnosolutionsolvedmyproblemandwhatIfindmostinterestingisthatitworksnormallyinPostman.

Requestheaderinthebrowserthatiscausingtheproblem.

Postmanheaderinwhichtherequestworkscorrectly.

    
asked by anonymous 31.01.2018 / 11:43

0 answers