Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
FormData() converts files to String

I cannot send the original data object from my form through axios to Spring Boot as is is a single object and Spring boot cannot get the @RequestParams for it. Therefore, I am putting the data a FormData object so that it can be sent to a Spring Boot application, however, whenever I append a file to the FormData object, it converts my file array to a string.

Here is the code:

const onSubmit = async (data) => {
        console.log(data, "Form data");

        let payload = new FormData();
        payload.append("JobName", data.JobName);
        payload.append("CandidateFile", data.CandidateFile);
        payload.append("ReferenceFile", data.ReferenceFile);
        console.log(...payload, "Payload")

        for(let pair of payload.entries()) {
            console.log(typeof pair[1]);
        }

        ...

In the console, data comes back with the data object, with files included:

{JobName: 'JobName', ReferenceFile: [File], CandidateFile: [File]}

The FormData payload, in the console, is:

(2) ['JobName', 'JobName']

(2) ['CandidateFile', '[object File]']

(2) ['ReferenceFile', '[object File]']

And all three typeof of the payload values come back as:

String

Is there any way I could send the files through with FormData?

I have tried using the files both in an array, and out, yet it still gives the same result.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda