node-glacier-uploader icon indicating copy to clipboard operation
node-glacier-uploader copied to clipboard

multiple files with uploader.js

Open yulian-zapata opened this issue 3 years ago • 2 comments

Hello, I have a question, how could I use to consecutively upload a list of files ?. now I am using uploader.js as my library.

regards

yulian-zapata avatar Mar 08 '21 13:03 yulian-zapata

Just use for .. loop or promise.all?

josser avatar Mar 08 '21 21:03 josser

Hello @josser

This is an example of how I am trying to send multiple files using promises

but when I try to upload a file it fails me

const tables = {
    pt_canje_a19m03: true,
    pt_estadistica_a19m03: true,
    pt_estadistica_resumen_a19m03: true,
    pt_log_habeas_a19m03: true,
    pt_perfil_a19m03: true,
    pt_publicacion_clics_a19m03: true,
    pt_publicacion_vistas_a19m03: true,
    pt_usuario_permisos_cliente_a19m03: true,
    pt_usuario_radius_a19m03: true
}

const uploadGlacier = (table) => {
    console.log('Initiating upload to', process.env.vaultName + "la tabla" + table);
    return new Promise((resolve, reject) => {
        try {
           //  here I use upload.js as my library
            let result = uploader.upload(
                process.env.DIR_BACKUPS + table + '.csv',
                process.env.vaultName,
                'us-east-1',
                20,
                'tabla migrada ' + table + 'date' + new Date())
           resolve(result)
        } catch (e) {
            reject(e)
        }
    })
    //}
}

const uploadFiles = () => {
    const promises = [];
    for (const table in tables) {
        promises.push(uploadGlacier(table))
    }
    Promise.allSettled(promises).then((results) => {
        results.forEach((result) => console.log(result))
    }).catch(e => {
        console.log("error")
        console.log(e)
    });
}

uploadFiles();

this is the result with error that gives me image

yulian-zapata avatar Mar 11 '21 13:03 yulian-zapata