ActiveStorage inferring file type from Tempfile

12 views
Skip to first unread message

Walter Lee Davis

unread,
Jan 29, 2018, 12:48:47 PM1/29/18
to Ruby on Rails: Talk
I was recently experimenting with Rails 5.2, particularly the ActiveStorage bit. I was attempting to allow a file attachment (PDF) to be thumbnailed on a as a PNG using some example code I found in the documentation:

image_tag @user.file.preview(resize: "640x280")

Tracing through the resulting error, it appeared to be mired in `identify` not being able to figure out that the Tempfile that AS created at the start of the preview task was a PDF. I had all of the dependencies installed on my Mac - `mupdf` and its predicate, `xquartz`. I haven't tried this on a Linux server yet. Has anyone else gotten this to work on their Mac?

Tracing through the code in ActiveStorage, I saw that it was supposed to create a Tempfile with the dot-suffix to match the original file, but in the error, I did not see that behavior. (And I know, dot-suffixes cannot be trusted at all.) I tried looking to see what could be overriding AS's code (maybe MiniMagick?) but I could not figure it out.

Thanks in advance,

Walter
Reply all
Reply to author
Forward
0 new messages