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

445
Views
La carga de archivos Jsp devuelve un flujo de entrada vacío para la carga de archivos

Estoy trabajando en la carga de un archivo jsp usando una llamada ajax y puedo presionar el controlador java en HttpServletRequest. Veo el archivo de varias partes recibido, pero cuando hago request.getInputStream.readAllBytes() , obtengo una matriz de bytes vacía.

La llamada ajax en javascript

 function saveFileUpload() { var data = new FormData() data.append("file", document.getElementById(fileName).files[0]) $.ajax({ type: 'POST', data: data, url: pageContext + "/upload", processData: false, contentType: false, success: function(data) {}, error: function(e) {} }); } }

En el controlador Java

 @RequestMapping(value = {"/upload"}, method = RequestMethod.POST) public void fileUpload ( HttpServletRequest request, HttpServletResponse response){ byte[] arr = request.getInputStream().readAllBytes(); System.out.println(arr.length); }

El código anterior imprime arr.length como 0. ¿Puede alguien decirme el motivo de este problema?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Supongo que está utilizando Springboot y su aplicación es compatible con multipart/form-data . Después de la versión 3.0 , la API de Servlet lo admite de forma nativa.

 @RequestMapping(value = "/upload", method = RequestMethod.POST) public void fileUpload(@RequestParam("file") MultipartFile file) throws IOException { if (!file.isEmpty()) { byte[] bytes = file.getBytes(); // and so on } }

Ajax de JQuery:

 function saveFileUpload() { let data = new FormData() data.append("file", document.getElementById(fileName).files[0]) $.ajax({ type: 'POST', data: data, url: pageContext + "/upload", processData: false, contentType: false, success: function(data) {}, error: function(e) {} }); }
over 4 years ago · Santiago Trujillo 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!