Ruby open-uri open method loses file extension opening images

Posted by Jimmy on Stack Overflow See other posts from Stack Overflow or by Jimmy
Published on 2012-06-13T13:26:20Z Indexed on 2012/11/12 17:00 UTC
Read the original article Hit count: 320

Filed under:
|
|

I'm using ruby 1.9.2 along with Rails 3.1.4 and Paperclip 2.4.5.

My issue is trying to save a paperclip attachment from a URI loses the file extension and saves the file without one resulting in issues with things like fancybox that require an extension.

Some example code:

uri = "http://featherfiles.aviary.com/2012-06-13/bbe5f0de1/0c5a672b88ea47ecb4631ac173e27430.png"
open(uri)
#=> #<File:/var/folders/zc/d69gxhzx10x_bvjrkqgyjgxr0000gn/T/open-uri20120613-27204-i6cldv>

Because there is no extension on the temp file paperclip is saving the file without one resulting in issues.

Has anyone run into this issue? I've seen multiple answers about using paperclip to store images from a URI but none seem to address the same problem we're running

© Stack Overflow or respective owner

Related posts about ruby

Related posts about paperclip