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

218
Vistas
Error 404 when uploading file with AJAX to Java Spring

i've been struggling for a while to send a file from html to my Java controller using AJAX and my nerves got to an end. I've read multiple answers on stack overflow but nothing worked for me. I am using Brave as browser.

This is my 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>

Here i just use a fake input to style the "pick file" button, don't mind what's happening here because in javascript the file gets picked correctly

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

    })
}

Java Controller

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

Everything i've try ends up in 404 error. I don't know if there is a problem with my browser or with my code but all the solutions from internet are not working for me

about 4 years ago · Juan Pablo Isaza
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