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

954
Vistas
¿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 Respuestas
Responde la pregunta

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 Denunciar
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