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

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