1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

FormData HTTP request sent by Angular is not readable by Spring backend

Discussão em 'Angular' iniciado por Jago, Maio 21, 2025.

  1. Jago

    Jago Guest

    I am sending a File in a POST request using Angular. I use standard HttpClient and set the payload as FormData in order to send multipart/form-data:

    const url = '...';
    const formData = new FormData();
    formData.append('file', file); // file is type File

    this.httpClient.post(url, formData);


    Since I don't override Content-Type header, Angular creates it for me, together with the multipart 'boundary'. That can be seen by copying the request as cURL in Chrome Dev tools:

    -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary0jzgUXpnrXuu4Fjt'


    However, the same cURL request shows, after all the headers (-H), the payload row which begins with --data-raw:

    --data-raw $'------WebKitFormBoundary0jzgUXpnrXuu4Fjt\r\n...


    Allegedly that --data-raw is not compatible with what the backend is expecting to read and is causing the request to fail when read.

    When doing the request from Postman, setting the same form-data format with a File, the cURL request shows a different payload row after the headers, beginning with --form:

    --form 'file=@"/path_to_file/file_name.ext"'


    What else could I set to the request so that Angular sends it with --form instead of --data-raw so that the Spring backend could read it?

    Continue reading...

Compartilhe esta Página