Tendría que encontrar una solución para enviar a través de una sola solicitud POST de axios lo siguiente:
¿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.
POST simple, puede enviar solo hasta 1 MB de datos binariosFormDataConsulte esta respuesta para obtener información.
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á