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

262
Visualizações
How to save content of a file into a variable and then use it on a request?

I'm trying to save content of a file (.xml) into a variable and then using it on body's request. You can see in the code below that i'm using readFile to get content of the file "xml.xml" and then saving its value to a variable named "upload". In the body's request I'm using "upload" variable to fill an api's parameter named "file". See:

it.only('TESTES', () => {
    cy.readFile('C:\\Users\\leonardo.pignato\\Desktop\\xml.xml').then(xml => {
        upload = xml

        cy.request({
            url: "/api/",
            method: "POST",
            headers: { 'Content-Type': 'form-data', 'Authorization': `bearer ${token}` },
            body: { file: upload }

        }).its('status').should('be.equal', 200)

    })

})

})

However, i get status 500 and this error: "error": "Cannot destructure property 'file' of 'httpRequest.files' as it is undefined."

Can someone tell me why this is happening?

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