title: Heroku - how to write into "tmp" directory?
body: <p>I need to use the <code>tmp</code> folder on Heroku (Cedar) for writing some temporarily data, I am trying to do that this way:</p>
  
  <pre><code>open("#{Rails.root}/tmp/#{result['filename']}", 'wb') do |file|
    file.write open(image_url).read 
  end
  </code></pre>
  
  <p>But this produce error </p>
  
  <pre><code>Errno::ENOENT: No such file or directory - /app/tmp/image-2.png
  </code></pre>
  
  <p>I am trying this code and it's running properly on localhost, but I cannot make it work on Heroku.</p>
  
  <p>What is the proper way to save some files to the <code>tmp</code> directory on Heroku (Cedar stack)?</p>
  
  <p>Thank you</p>
  
  <p><strong>EDIT:</strong> 
  I am running method with Delayed Jobs that needs to has access to the tmp file.</p>
  
  <p><strong>EDIT2:</strong>
  What I am doing:</p>
  
  <pre><code>files.each_with_index do |f, index|
        unless f.nil?
          result = JSON.parse(buffer)
          filename = "#{Time.now.to_i.to_s}_#{result['filename']}" # thumbnail name
          thumb_filename = "#{Rails.root}/tmp/#{filename}"
  
          image_url = f.file_url+"/convert?rotate=exif"
  
          open("#{Rails.root}/tmp/#{result['filename']}", 'wb') do |file|
            file.write open(image_url).read 
          end
  
          img = Magick::Image.read(image_url).first
          target = Magick::Image.new(150, 150) do
            self.background_color = 'white'
          end
          img.resize_to_fit!(150, 150)
          target.composite(img, Magick::CenterGravity, Magick::CopyCompositeOp).write(thumb_filename)
  
          key = File.basename(filename)
          s3.buckets[bucket_name].objects[key].write(:file =&gt; thumb_filename)
  
          # save path to the new thumbnail to database
          f.update_attributes(:file_url_thumb =&gt; "https://s3-us-west-1.amazonaws.com/bucket/#{filename}")
        end
      end
  </code></pre>
  
  <p>I have in database information about images. These images are stored in Amazon S3 bucket. I need to create thumbnails to these images. So I am going through one image by another one, load the image, temporarily save it, then resize it and afterwards I will upload this thumbnail to S3 bucket.</p>
  
  <p>But this procedure doesn't seems to be working on Heroku, so, how could I do that (my app is running on Heroku)?</p>