lundi 9 mars 2015

Create / Rename a tempfile in rails using open() method

I am trying to create a tempfile, which i am downloading from a URL: for example this JPEG image which has no extension in the URL:


http://ift.tt/1MmeteZ


You can see it does not have a .jpg extension... So i'd like to save it as a tempfile, but before saving append the .jpg extension to it. Is this possible? Or if thats not possible, rename the tempfile after saving?


Right now, i am able to create the temp file by saying file = open("http://ift.tt/1MmeteZ")


Which writes the temp file... But this does not help, as the temp file also has no extension


#<Tempfile:/var/folders/3m/t1v11gzj32n0fdbhwr823y600000gn/T/open-uri20150309-21935-qw7870>


Aucun commentaire:

Enregistrer un commentaire