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

238
Vistas
JS client doesn't read response when server aborts file upload

We have an API (Spring Boot) for file uploads. If file exists it returns 409.

But js client doesn't read this response and fails with error "net::ERR_CONNECTION_ABORTED".

From wireshark dump I see that the backend sends the response and then closes the connection:

enter image description here

I think the problem is that js client doesn't read the response as soon as it available. However, Postman is able to read the response correctly.

Is it possible to implement Postman's behavior in javascript? I've tried to read response stream with Fetch API, but no luck.

Sample client code:

function uploadFile() {
try {
    console.log("Start file upload");

    const selectedFiles = document.getElementById('input').files;
    if (selectedFiles.length == 0) {
        alert("No file selected");
        return;
    }

    const file = selectedFiles[0];

    return fetch("http://localhost:9091/api/v1/storage/upload?fileId=/upload-test/test.mp4", {
        method: 'PUT',
        body: file,
        headers: {
            'Content-Type': 'application/octet-stream'
        },
    })
        .then(response => {
            console.log("Processing response");

            const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();

            return pump();

            function pump() {
                return reader.read().then(({ value, done }) => {
                    if (done) {
                        console.log("Finished stream reading");
                        return;
                    }

                    console.log(value);
                    return pump();
                });
            }
        })
        .catch((err) => console.error("error:", err));
} catch (error) {
    console.log(error);
}

}

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