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

140
Views
Parsing and appending binary chunks in Javascript and Golang

I'm chunking large uploads in Javascript and trying to parse them to continuously append to disk on Golang.

Javascript Chunking Logic

function fileChunker(file, startChunk) {
  const chunkMax = Math.min(startChunk + CHUNK_SIZE, file.size);
  const fileChunk = file.slice(startChunk, chunkMax);
  const chunkForm = new FormData();
  chunkForm.append("file", fileChunk);
  chunkUploader(chunkForm, startChunk, file)
}

function chunkUploader(chunkForm, startChunk, file) {
  var oReq = new XMLHttpRequest();
  oReq.timeout = 2000

  oReq.open("POST", "http://localhost:8300/upload", true);
  oReq.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 

  oReq.onload = function (oEvent) {
    const updatedStartChunk = startChunk + CHUNK_SIZE;
    if (updatedStartChunk < file.size) {
      fileChunker(file, updatedStartChunk);
      return
    }
  };

  console.log(chunkForm)
  oReq.send(chunkForm);
}

Golang Parsing Logic

package main

import (
    "fmt"
    "net/http"
)

func uploadHandler(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Access-Control-Allow-Origin", "*")
    w.Header().Set("Access-Control-Allow-Headers", "*")
    w.Header().Set("Access-Control-Allow-Methods", "*")

    if err := r.ParseMultipartForm(0); err != nil {
        fmt.Fprintf(w, "Err parsing form.")
    }
    fmt.Println(r.FormValue("file"))
}

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/upload", uploadHandler)
    http.ListenAndServe(":8300", mux)
}

Data On Each POST iteration in the browser:

enter image description here

Prior to sending the request, the form data looks as expected (chunked sizes of 10kb). Trying to print this data is just empty on the server. Is there any way to validate the data I'm sending on the serverside? I feel like this isn't being parsed correctly and I'm not sure why.

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!