Topic: temp file question

I am trying to create a paperclip attachment from a temp file, but I am finding that when I do:

temp_file = Tempfile.new("foo.xyz")

I get:
#<File:/var/folders/SY/SYCFBso-HzCi-GcKlkw3UE+++TI/-Tmp-/foo,12928,0.xyz>")

And then later on, when the paperclip attachment is served, the file I receive is foo_12928_0.xyz

I am wondering how can I get rid of those numbers in the file name?

thanks.

-patrick

Last edited by patrick99e99 (2010-05-02 14:36:12)

Re: temp file question

Well you could overwrite the Tempfile.make_tmpname method:

http://dev.thoughtbot.com/paperclip/cla … pfile.html

But then you could get problems if you had files with the same name being uploaded. You'd probably be better doing something with callbacks like in these examples:

http://almosteffortless.com/2009/03/22/ … paperclip/
http://www.davesouth.org/stories/make-u … ttachments

And do something like this:


filename.gsub(/,\d+,\d(\.\w{1,3})$/, $1)

(disclaimer: haven't tested smile)

Alex

Last edited by alexpt (2010-05-03 04:44:56)

Re: temp file question

Cool,

Thanks alex..  That worked out great...

-patrick