简体   繁体   中英

Unable to use fs and and webshot with Meteor on server side (galxy hosted)

I am currently running a meteor app on galaxy that creates PDF based on input from the user.

I've been using webshot-node and FS to temporarly save the PDFs and then it direct download on the user side.

Because of some other bugs I solved, I deployed the new projects again on Galaxy, but it is now imposssible to generate the PDF anymore (nothing as changed on this part of the code).

The error I get is the following:

Error: ENOENT: no such file or directory, open /app/bundle/programs/web.browser/app/cv_resume.pdf 
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/app/bundle/programs/web.browser/app/cv_resume.pdf'

As stated, I didn't changed anything on the generation of the PDFs, so I'm wondering if anyone of you got similar error using webshot and FS on server side.

By the way, it works perfectly fine on my local machine.

Oh and here is the code of the generation in case someone would like to give it a try:

var myDocument1 = Personalinfo.findOne({ email: creator });
      // SETUP
      // Grab required packages
      var fs = Npm.require('fs');
      var Future = Npm.require('fibers/future');
      var webshot = Npm.require('webshot-node');
      var fut = new Future();
      var meteorRoot = fs.realpathSync(process.cwd() + "/../" );
      var publicPath = meteorRoot + "/web.browser/app/";
      var fileName = publicPath + "cv_resume.pdf";

      // GENERATE HTML STRING
      var css = Assets.getText('style.css');
      SSR.compileTemplate('layout', Assets.getText('layout.html'));
      Template.layout.helpers({
        getDocType: function () {
          return "<!DOCTYPE html>";
        }
      });
      SSR.compileTemplate('resume', Assets.getText('resume.html'));

      // PREPARE DATA
      var html_string = SSR.render('layout', {
        css: css,
        template: "resume",
        data: myDocument1
      });

      var options = {
        "paperSize": {
          "format": "A4",
          "orientation": "portrait",
          "margin": "0.8cm"
        },
        siteType: 'html'
      };

      // Commence Webshot
      webshot(html_string, fileName, options, function (err) {
        fs.readFile(fileName, function (err, data) {
          if (err) {
            return console.error(err);
          }
          fs.unlinkSync(fileName);
          fut.return(data);
        });
      });
      
      let pdfData = fut.wait();
      let base64String = Buffer.from(pdfData).toString('base64');
      if (fullName != "") {
        return [base64String, fullName];
      } else {
        return base64String;
      }

Hope someone can help me, I've been stuck with this for a long time now. At disposal if anyone needs more info.

Thanks for the clarification. Seems like you just need a folder with write access where webshot can put the pdf and from where you can then read it again. In that case, just use /tmp :

var publicPath = "/tmp/_webshot/";
var fileName = publicPath + "cv_resume.pdf";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM