Closed juttameerhamza closed 4 years ago
Help please i have to complete this task Here is my code
const fs = require('fs'); const express = require('express'); const multer = require('multer'); const signer = require('node-signpdf').default; const app = express(); const fileStorage = multer.diskStorage({ destination: (req, file, cb) => { cb(null, `./uploads`); }, filename: (req, file, cb) => { let fileName = file.originalname.split(' ').join('-'); cb(null, Date.now().toString() + '-' + fileName); } }); const upload = multer({ storage: fileStorage }); app.post('/pdf/sign', upload.fields([{ name: 'pdf' }, { name: 'certificate' }]), (req, res) => { const pdf = req.files.pdf[0].path; const certificate = req.files.certificate[0].path; const signedPdf = signer.sign( fs.readFileSync(pdf), fs.readFileSync(certificate) ); fs.writeFileSync(`${__dirname}/upload/${req.files.pdf[0].filename}-signed`, signedPdf); res.status(200).json({ message: 'success', }); }); const port = 3000; app.listen(port, () => console.log(`Appliction is listening on ${port}`));
Could you maybe attach an example PDF file that fails?
I resolve it thanks @vbuch vbuch
Hey @juttameerhamza how did you solve this problem?
Help please i have to complete this task Here is my code