Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
juttameerhamza opened this issue Jan 1, 2020 · 4 comments

Comments

@juttameerhamza
Copy link

juttameerhamza commented Jan 1, 2020

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}`));
@juttameerhamza juttameerhamza changed the title Uploading pdf and certificate using multer and sign pdf but there is error Uploading pdf and certificate using multer and sign pdf but there is error Could not find ByteRange placeholder: /ByteRange [0 /********** /********** /**********] Jan 1, 2020
@vbuch
Copy link
Owner

vbuch commented Jan 10, 2020

Could you maybe attach an example PDF file that fails?

@juttameerhamza
Copy link
Author

I resolve it thanks @vbuch vbuch

@lucasmassi
Copy link

Hey @juttameerhamza how did you solve this problem?

1 similar comment
@erickximenes
Copy link

Hey @juttameerhamza how did you solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants