在 Heroku 上使用 PDFKit 生成文件 - 没有这样的文件或目录 [英] Generating file with PDFKit on Heroku - No such file or directory

查看:46
本文介绍了在 Heroku 上使用 PDFKit 生成文件 - 没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PDFKit 从 Heroku Cedar 上的 Resque 作业中的给定 url 创建 pdf.我的代码看起来像:

I'm using PDFKit to create pdfs of from a given url within a Resque job on Heroku Cedar. My code looks like:

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

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

I then upload the file using fog to S3 for permanent storage. This job usually works, but also fails maybe a third of the time with:

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

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

Manually running through the code in console will produce the same error.

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

According to the Heroku docs, I should be able to write a temporary file anywhere in the app's directory on Cedar. I've tried creating the tmp directory first (in console) but that didn't seem to change anything. Neither did saving to "#{Rails.root}/tmp/#{SecureRandom.hex}.pdf".

任何想法将不胜感激.

更新

控制台中的完整错误是:

The full error in console is:

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,我不确定在哪里添加此标志.

It seems that maybe this is an error coming from wkhtmltopdf, however, I'm not sure where to add this flag if I'm using wkhtmltopdf via PDFkit.

推荐答案

看起来像我第二次发布的错误建议的解决方案是忽略加载错误.我这样做了:

Looks like the solution, as the error I posted second suggested, was to ignore the load error. I did this with:

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

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

I wasn't seeing this warning at first because Resque was only showing me the final error. Thanks @ctshryock, your question made me think a little more about exactly where this error was coming from.

这篇关于在 Heroku 上使用 PDFKit 生成文件 - 没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆