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

143
Vistas
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
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