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

288
Visualizações
Javascript: Upload a file from inside a tar file

I have an HTML form that is used to upload a file to the server. This works correctly but now I am trying to expand the capability such that I select a tar file that consists of two binary files. Then untar the files and based on certain conditions either upload the first or the second file.

This is what I have done so far

  • use FileReader to read the tar file as ByteArray
  • use untar from js-untar to untar both file

I need help to figure out how to take the ByteArray for either files and add then to the FormData so that I can upload them.

Any help would be appreciated.

Here are snippets from my code

HTML Form

<form id="upform" enctype="multipart/form-data"
 action="cgi-bin/upload2.cgi">
Firmware file: <input id='userfile' name="userfile" type="file" width=50 >
<input type
="submit" name="submitBtn" value="send file">
</form>

Untar code

function sendData() {

    var formData = new FormData(form);
    var action = form.getAttribute('action');
    filesize = file.files[0].size;
    var reader = new FileReader();

    reader.onload = function() {
        untar(reader.result).then(
            function (extractedFiles) { // onSuccess
                console.log('success');
                formData.delete('userfile');
                var reader2 = new FileReader();
                reader2.onload = function() {
                    formData.append('userfile', reader2.result);
                    upload(formData);
                }
                var blob = new Blob([extractedFiles[0]], {type : 'multipart/form-data'});
                reader2.readAsDataURL(blob);
                
                // var f = URL.createObjectURL(blob);
                
                
            },
            function (err) {
                console.log('Untar Error');
            }
        )
        
    };
    reader.readAsArrayBuffer(file.files[0]);

    return;
}

function upload(formData) {
    var action = form.getAttribute('action');
    reqUpload.open('POST', action, true);
    reqUpload.onreadystatechange = uploadState;
    document.body.style.cursor = "wait";
    var ld = document.getElementById("load");
    ld.classList.add("loader");
    reqUpload.send(formData);
    document.getElementById('progress').style.display = "block";
    progTimer = setInterval(ping, 10000);
    uploadStarted = true; 
    return;

}
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