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

236
Views
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
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!