vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
723 stars 178 forks source link

Uploading pdf and certificate using multer and sign pdf but there is error Could not find ByteRange placeholder: /ByteRange [0 /********** /********** /**********] #52

Closed juttameerhamza closed 4 years ago

juttameerhamza commented 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}`));
vbuch commented 4 years ago

Could you maybe attach an example PDF file that fails?

juttameerhamza commented 4 years ago

I resolve it thanks @vbuch vbuch

lucasmassi commented 4 years ago

Hey @juttameerhamza how did you solve this problem?

erickximenes commented 4 years ago

Hey @juttameerhamza how did you solve this problem?