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

394
Vistas
Gulp / nodejs download zip file from AWS S3 corrupted: using aws-sdk

I trying to download zip file from AWS S3 using aws-sdk for javascript in gulp. My code download file, but it corrupted. And i can't uncompress that with 7zip program and zip command. Maybe has some encode that i missing.

Here my code:

require('dotenv').config();
const AWS = require('aws-sdk');
const fs = require('fs');
const commandLineArgs   = require('command-line-args');
const options = commandLineArgs([
    {name: 'filename', alias: 'f', type: String},
]);

gulp.task('zipFromS3', function() {
    var AWS = require('aws-sdk');
    var fs = require('fs');
    AWS.config.update({accessKeyId: process.env.AWS_ACCESS_ID,secretAccessKey: process.env.AWS_ACCESS_SECRET});

    var s3bucket = new AWS.S3({params:{Bucket: env.aws.access_backups.bucket}});
    return new Promise(function(resolve,reject){
        if(options.filename == null || typeof options.filename == 'undefined'){
            return reject();
        }
        let filename = options.filename; //'2017-04-06.zip'
        var file = fs.createWriteStream(env.server.downloads + '/'+filename);
        var params = {
            Key: filename,
            Bucket: env.aws.access_backups.bucket
        };

        s3bucket.getObject(params, function(err, data){
            if (err) {reject();}
        }).createReadStream()
         .on('error', function(err){
            console.log(err);
            reject();
        })
        .on('end', function (chunk){
             resolve();
        }).pipe(file);
    });
});

I use this script to download some .txt file from s3, and this works well. If i go to my bucket and download my zip file directly from aws site, it works well too.

The zipped file was created in gulp too. This is the code to create the zip file (before send to AWS this zip can be uncompressed correctly).

const zip = require('gulp-zip');
const env = readConfig('.env.json', { override: true });
gulp.task('zip', () => {
    let now = new Date();
    let m   = now.getMonth();
    let d   = now.getDate();
    m++;
    if(m < 10){m = "0"+m;}
    if(d < 10){d = "0"+d;}

    let name = now.getFullYear()+'-'+m+'-'+d;
    if(typeof options.filename != 'undefined' && options.filename != null){
        name += "_"+options.filename;
    }

    return gulp.src(env.server.dist+"/**")
        .pipe(zip(name + ".zip"))
        .pipe(gulp.dest(env.server.zipfolder));
});
about 4 years ago · Santiago Trujillo
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