Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!