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

952
Views
¿Cómo enviar texto y datos binarios en la solicitud de publicación de axios?

Tendría que encontrar una solución para enviar a través de una sola solicitud POST de axios lo siguiente:

  1. estructura json
  2. archivo binario (archivo de Excel)

¿Cómo puedo conseguir esto?

 let files = event.target.files; const fileReader = new FileReader(); fileReader.readAsText(files[0], null); fileReader.onload = () => { this.fileContent = fileReader.result; let binaryDataForObject = this.fileContent; let referenceDataStructure = { textData: textDataForObject, binaryData: binaryDataForObject, referenceDataFileExtension: this.referenceDataFileExtension, userProvidedDataTypes: this.columnTypes }; } this.axios .post( "http://url, referenceDataStructure )

Esto funciona técnicamente, pero en el lado de Java no pude entender cómo decodificar los datos binarios (codificados como una cadena) para que se traten como un archivo de Excel.

Gracias de antemano por cualquier respuesta significativa. Lubos.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

  1. Con una solicitud POST simple, puede enviar solo hasta 1 MB de datos binarios
  2. Para enviar binario y texto en una solicitud, debe usar FormData

Consulte esta respuesta para obtener información.

Actualización 14.12

Cómo logré hacer esto en mi proyecto reciente fue usando FormData

Entonces, primero debe obtener el archivo como un blob:

 const fileReader = new FileReader() // Here we will get the file as binary data fileReader.onload = () => { const MB = 1000000; const Blob = new Blob([fileReader.result], { // This will set the mimetype of the file type: fileInputRef.current.files[0].type }); const BlobName = fileInputRef.current.files[0].name; if (Blob.size > MB) return new Error('File size is to big'); // Initializing form data and passing the file as a param const formData = new FormData(); // file - field name, this will help you to read file on backend // Blob - main data to send // BlobName - name of the file, default it will be name of your input formData.append('file', Blob, BlobName); // Append json data formData.apped('some-key', someValue) // then just send it as a body with post request fetch('/api/submit-some-form-with-file', { method: 'POST', body: formData }) // Handle the rest .then() } fileReader.readAsArrayBuffer(fileInputRef.current.files[0])

Puede envolver este ejemplo en la función de envío de manejo en reaccionar y me gusta o usarlo tal como está

about 4 years ago · Santiago Gelvez Report
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!