在DigitalOcean上,Ubuntu 14.04的Meteor中,Webshot失败了。

6
我正在使用这段代码生成PDF文件:
let fileUri = process.env.PWD + '/storage/orders-pdf/' + fileName;

// Commence Webshot
webshot(html_string, fileUri, options, function(error) {
  fs.readFile(fileUri, function (err, data) {
    if (err) {
        return console.log(err);
    }

    fs.unlinkSync(fileUri);
    fut.return(data);
  });
});

let pdfData = fut.wait();

但是它会抛出以下错误:
{ [Error: ENOENT, open '/opt/holi/storage/orders-pdf/Attributes.pdf']
   errno: 34,
   code: 'ENOENT',
   path: '/opt/holi/storage/orders-pdf/Attributes.pdf' }

尝试使用npm包https://github.com/brenden/node-webshot。代码在本地主机上运行正常,但在服务器上失败并抛出以下错误:

编辑:

即使在没有的情况下运行webshot:

fs.readFile(fileUri, function (err, data) {
  if (err) {
    return console.log(err);
  }

  fs.unlinkSync(fileUri);
  fut.return(data);
});

文件未被创建。

编辑2:

Webshot抛出错误:[Error: PhantomJS exited with return value 2]

编辑3: 实际问题:https://github.com/brenden/node-webshot/issues/123


enoent - 没有这样的文件/目录。你确定路径/文件存在吗? - Marc B
好的,操作系统通常不会说谎;-)您能展示一下运行ls -l /opt/holi/storage/orders-pdf/Attributes.pdf时得到的结果吗? - Christian Fritz
drwxr-xr-x 2 meteoruser root 4096 Feb 3 08:54 orders-pdf - R-J
1
创建了什么?我不明白。我只看到了readFile,而且我还看到你正在删除文件(unlink)。 - Christian Fritz
顺便问一下,你有检查 webshot 返回的 error 吗?也许出了问题。 - Christian Fritz
显示剩余7条评论
1个回答

0

我曾经遇到过类似的问题,花费了大部分时间来尝试解决这个问题。最终我添加了以下代码:

"phantomPath": "/usr/bin/phantomjs"

将此文本翻译为中文:将其添加到我的Webshot选项对象中。我使用的幽灵路径是mup在您的服务器设置上安装phantomjs的位置。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接