JS new file method, file gets corrupted

Hello,

I have a problem, I’m working with the meteor zip uploader where files inside zip needs to be extracted first before saving it to server. My codes and the library I’m using is already able to extract the files inside zip, however, the problem is… I can’t recreate the extracted files as a valid file type before moving it to server. In my case I’m using s3 server and meteor-slingshot uploader. Here’s my full codes for zip uploader that create a corrupted files on the server.

var filesInput = file;
                            var res;
                    
                            var reader = new FileReader();
                            reader.readAsBinaryString(filesInput);
                    
                            reader.onloadend = function(e){
                                var myZip = e.target.result;                 
                                var unzipper = new JSUnzip(myZip);
                    
                                unzipper.readEntries();    
                                var myFiles = unzipper.entries;    
                                
                                let z_num_files_uploaded = 0;
                                let z_temp_files = [];
                                let z_num_uploader_files = myFiles.length;
                                
                                for(var i=0; i<myFiles.length; i++) {                                  
                                    
                                    var name = myFiles[i].fileName; // This is the file name
                                    var _fxt = name.split('.').pop().toLowerCase();
                                    //var content = JSInflate.inflate(myFiles[i].data); // this is the content of the files within the zip file.
                                    console.log(myFiles[i]);                                 
                                   
                                    
                                    var zfile = new File([myFiles[i].data], name, {type: _MIME_TYPES[_fxt], lastModified: Date.now()});                                  
                                    
                                    console.log(zfile);
                                    
                                    var uploader = new Slingshot.Upload("myFileUploads");
                    
                                    uploader.send(zfile, function (error, downloadUrl) {
                                      if (error) {
                                        alert (error);
                                      }
                                      else {
                                        
                                        var new_fname = downloadUrl.split('/').pop(); 
                                          
                                       z_temp_files.push({
                                           orig_name : zfile.name,
                                           new_name : new_fname,
                                           full_url : downloadUrl,
                                           description : zfile.name,
                                           size : zfile.size,
                                           deleted : false,
                                       });
                                       
                                       z_num_files_uploaded++;
                                       
                                       if(z_num_files_uploaded == z_num_uploader_files){ //check if last uploaded file is done
                                               let _p = {};
                                               _p['album_name'] = _album_name + ' - ' + filesInput.name;
                                               _p['job_number'] = Number(Session.get('current_id'));
                                               _p['description'] = '';
                                               _p['files'] = z_temp_files;
                                               
                                               alertify.message("Saving Zip File(s)...");
                                               
                                               Meteor.call('_addAttachment', _p, function(err, rs){
                                                   if(rs){
                                                       alertify.success("Successfully uploaded zip file(s).");
                                                   }else{
                                                       alertify.error("Failed to upload zip file attachment.");
                                                   }
                                               });
                                       }
                                       
                                      }
                                    });
                                    
                                    
                                }
                            }

Any help are appreciated. :slight_smile:

Thanks!