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

186
Vistas
pdf encryption and uploading aws S3 not working

In this code i am trying to create pdf file and encrypting, i am able to create pdf encryption, in this code i am creating one Tempfile in my local machine after that i am encrypting that file and in here 'qpdf --encrypt Decorpot test 40 -- ${tempFileName} --replace-input' i am just replacing the non encrypted file with encrypted file and its storing correctly as a encrypted file in local machine,but when i am going to upload in s3 aws only non encryted file is added. i tried so many methods..please help me.. ThankYou

    module.exports.generateChecklistPdf2 = function () {
    return new Promise((resolve, reject) => {
    let htmlFilePath = '';
    htmlFilePath = path.join(__dirname, '../static/html/checkList.html');
    htmlFilePath = htmlFilePath.replace(new RegExp(/\\/g), '/');
    pdfFilePath = path.join(__dirname, '../uploads/' + Math.ceil(Math.random() * 
    810000) + '.pdf');
    pdfFilePath = pdfFilePath.replace(new RegExp(/\\/g), '/');
    let date = new Date();
    return ejs.renderFile(htmlFilePath, { moment: moment, date }, {}, function (err, 
    htmlFile) {
        if (err) return console.log(err);
        var tempFileName = pdfFilePath;
        var file = fs.createWriteStream(tempFileName);
        assetsPath = path.join(__dirname, '../static/');
        assetsPath = assetsPath.replace(new RegExp(/\\/g), '/');
        options = {
            base: 'file:///' + assetsPath,
        }


        setTimeout(() => {
            var cmd = `qpdf --encrypt Decorpot test 40 --  ${tempFileName} 
            --replace-input`;
            exec(cmd, function (err) {
                if (err) {
                    console.error('Error occured: ' + err);
                } else {
                    console.log('PDF encrypted :)', tempFileName);
                }
            });
        }, 1000)

        return pdf.create(htmlFile, options).toStream(function (err, stream) {
            stream.pipe(file).on('close', () => {
                formData = {
                    customerName: "customername",
                    file: fs.createReadStream(pdfFilePath)
                }
                let url = '';
                if (process.env.NODE_ENV == 'production') {
                    url = 'http://13.233.26.162:5003/api/file/upload';
                } else {
                    url = 'http://localhost:5003/api/file/upload';
                }
                return request.post({ url: url, formData: formData },         
                function (err, res) {
                    if (err) return console.log(err);
                    console.log(res.body)
                    let resolveObject = {};
                    resolveObject.pdfUrl = res.body;
                    resolve(resolveObject);
                  });
               });
               });

             });
            });
           }
about 4 years ago · Juan Pablo Isaza
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