Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda