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

134
Visualizações
nulls are removed from the binary file when I send it to the server

I have thttpd server on embedded device. I want to make firmware update, so i need to send binary files via Ethernet to thttpd server.

Server have recieving file, BUT when i check file in server folder it have smaller size and seems like all 0x00 in file has beed removed. I think that somewhere in the course of this HTTP transaction, the data from the file is interpreted as text and 0x00 is interpreted as an empty field, but I do not know where, how to fix this.

I try to upload file on server with this code:

<form method="post" enctype="multipart/form-data">
<input id="jic-file" type="file" onchange="upload_firmware(this)">
</form>

<script>
async function upload_firmware(inp)
{
    let formData = new FormData();
    let fw = inp.files[0];
    formData.append("firmware", fw);
    const ctrl = new AbortController()
    setTimeout(() => ctrl.abort(), 10000);
    try {
       let r = await fetch("new_jic.cgi",
         {method: "POST", body: formData, signal: ctrl.signal});
       console.log('HTTP response code:',r.status);
    } catch(e) {
      console.log('Problem with uploading firmware...:', e);
    }
}
</script>

And recieve file with new_jic.cgi file:

#!/bin/sh

if [ "$REQUEST_METHOD" = "POST" ]; then
    if [ "$CONTENT_LENGTH" -gt 0 ]; then
        in_raw=$(cat)
        echo  $in_raw > raw.jic;
        boundary=$(echo -n "$in_raw" | head -1 | tr -d '\r\n');
        filename=$(echo -n "$in_raw" | grep --text --max-count=1 -oP "(?<=filename=\")[^\"]*");
        file_content=$(echo -n "$in_raw" | sed '1,/Content-Type:/d' | tail -c +3 | head --lines=-1 | head --bytes=-2);
        #echo "boundary: $boundary"
        #echo "filename: $filename"
        echo  $file_content > $filename;
    fi
fi
exit 0

Also try this code:

<script>
async function upload_firmware(inp)
{
       var fw = document.querySelector('input[type=file]').files[0];
       var bloob = new Blob([fw]);
       let r = await fetch("new_jic.cgi",
         {method: "POST", body: bloob});
       console.log('HTTP response code:',r.status);
}
</script>
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