5

I need to upload files and then parse them using paperclip?

Currently it is uploaded in the /system folder, which isn't allowed in heroku.

I don't need the uploads to be persistent...I parse it and then store them.

So I'd like to be able to save into /tmp and then parse, and then let it get blown away later.

Thoughts on how to do this (if I should do this)?

Satchel
  • 16,414
  • 23
  • 106
  • 192
  • hi, the solution you specified as setting :path=>"" doesn't work. do you mean blank string by "" or something else? as in setting a path in "". – Özgür Aug 16 '10 at 15:28
  • no I don't think it was to set a blank string, it was to set the actual path... – Satchel Aug 16 '10 at 19:58
  • the format is in the answer for :url – Satchel Aug 16 '10 at 19:59
  • @Angela hey i am also currently developing a facebook app which will allow users to upload import on tmp directory and it will be posted on facebook.But i am struggling to find what is the absolute path of /tmp directory of heroku.guess u have worked on it 2 years back..so any help?? – World Gamer Jan 06 '13 at 15:31

1 Answers1

2

Heroku's docs say to use Tempfile.

Well, it says in the doc:

There are two directories that are writeable: ./tmp and ./log (under your application root). If you wish to drop a file temporarily for the duration of the request, you can write to a filename like #{RAILS_ROOT}/tmp/myfile_#{Process.pid}. There is no guarantee that this file will be there on subsequent requests (although it might be), so this should not be used for any kind of permanent storage

Then, if you click on the Adam Wiggins link below that, he says this is available through the Tempfile interface.

Using Tempfile is easy, but your file may not exist if heroku considers read/write file operations different processes.

# tempfile_example.rb
require 'tempfile'

# defaults to Dir::tempdir
x = Tempfile.new('imagefile.png') 

puts x.path

Edit: The Answer

The answer is actually to set :path => " " ... but you were close.... – Angela

Joseph Yaduvanshi
  • 20,241
  • 5
  • 61
  • 69
  • Hi there and thanks. Should I stick this code into the same controller where I am calling paperclip? I guess I'm not clear how to use this within a Paperclip environment since it is the paperclip gem which puts it into the system folder. – Satchel Jun 29 '10 at 16:42
  • @Angela: I've never used paperclip, but it looks like you can specify the url in `has_attached_file` options, e.g. `:url => "/tmp/:attachment/:id/:style_:filename"` – Joseph Yaduvanshi Jun 29 '10 at 18:43
  • That options is documented here: http://dev.thoughtbot.com/paperclip/classes/Paperclip/ClassMethods.html – Joseph Yaduvanshi Jun 29 '10 at 18:43