Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda