【问题标题】:Generating file with PDFKit on Heroku - No such file or directory在 Heroku 上使用 PDFKit 生成文件 - 没有这样的文件或目录
【发布时间】:2013-03-17 18:21:03
【问题描述】:

我正在使用 PDFKit 从 Heroku Cedar 上的 Resque 作业中的给定 url 创建 pdf。我的代码如下:

kit = PDFKit.new(url)
pdf = kit.to_file("/tmp/#{SecureRandom.hex}.pdf")

然后我使用雾将文件上传到 S3 以进行永久存储。这项工作通常有效,但也有三分之一的时间失败:

No such file or directory - /tmp/a05c165fc80878b75fd15c447695de71.pdf

在控制台手动运行代码会产生同样的错误。

根据 Heroku 文档,我应该能够在 Cedar 上应用程序目录的任何位置写入临时文件。我尝试过首先创建 tmp 目录(在控制台中),但这似乎并没有改变任何东西。也没有保存到“#{Rails.root}/tmp/#{SecureRandom.hex}.pdf”。

任何想法将不胜感激。

更新

控制台中的完整错误是:

Error: Failed loading page http://grist.org/living/you-look-great-in-green-clothing-industry-gets-a-makeover-maybe.html
(sometimes it will work just to ignore this error with --load-error-handling ignore)
Errno::ENOENT: No such file or directory - /tmp/55a1d418074736decfd4e123d8e2bba2.pdf

这似乎是来自 wkhtmltopdf 的错误,但是,如果我通过 PDFkit 使用 wkhtmltopdf,我不确定在哪里添加此标志。

【问题讨论】:

  • " 然后使用雾上传文件到 S3" 这都是在同一个工作进程中完成的,是吗?否则,您可能会写入一个测功机的 tmp 并尝试从另一个测功机访问,这是行不通的。
  • 嗨。是的,这是在同一个工作进程中完成的。第二行其实是 object.pdf = kit.to_file("/tmp?#{SecureRandom.hex}.pdf");对象.保存。在对象上调用 save 会触发雾上传图像。
  • @middkidd 问题解决了吗?

标签: ruby-on-rails heroku resque pdfkit cedar


【解决方案1】:

看起来解决方案,正如我第二次发布的错误所建议的那样,是忽略加载错误。我这样做了:

PDFKit.configure do |config|
  config.default_options[:load_error_handling] = 'ignore'
end

一开始我没有看到这个警告,因为 Resque 只显示了最后一个错误。谢谢@ctshryock,你的问题让我对这个错误的确切来源有了更多的思考。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 2012-12-13
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    相关资源
    最近更新 更多