【发布时间】: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