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

219
Views
Error 404 al subir archivo con AJAX a Java Spring

He estado luchando por un tiempo para enviar un archivo desde html a mi controlador Java usando AJAX y mis nervios terminaron. He leído varias respuestas sobre el desbordamiento de pila, pero nada funcionó para mí. Estoy usando Brave como navegador.

Este es mi HTML:

 <div> <button type="button" onclick="uploadFile()">Import</button> <div class="custom-buttons"> <button onclick="clickRealFile()"type="button" name="button">Pick file</button> <input onchange="changeInputText(this)" id="real-file-second" type="file" name="file" hidden="hidden"> <p style="margin-left: 0.3rem;" id="custom-text">Upload file</p> </div> </div>

Aquí solo uso una entrada falsa para diseñar el botón "seleccionar archivo", no importa lo que esté sucediendo aquí porque en javascript el archivo se elige correctamente

JAVASCRIPT

 function uploadFile() { let formData = new FormData(); console.log($("#real-file-second")[0].files[0]) formData.append("file", $("#real-file-second")[0].files[0]); $.ajax({ url: encodeURI(window.location.origin + "/upload"), type: 'POST', contentType: false, cache: false, processData: false, data: formData }) }

Controlador Java

 @PostMapping("/upload") public void importProducts(@RequestParam("file") MultipartFile file) throws IOException { System.out.println("I've reached here"); }

Todo lo que intento termina en un error 404. No sé si hay un problema con mi navegador o con mi código, pero todas las soluciones de Internet no me funcionan.

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!