ruby-on-rails – Heroku – 如何写入“tmp”目录?

我需要使用Heroku(Cedar)上的tmp文件夹来编写一些临时数据,我试图这样做:
open("#{Rails.root}/tmp/#{result['filename']}",'wb') do |file|
  file.write open(image_url).read 
end

但这会产生错误

Errno::ENOENT: No such file or directory - /app/tmp/image-2.png

我正在尝试这个代码,它在localhost上正常运行,但我不能让它在Heroku上运行.

将一些文件保存到Heroku(Cedar堆栈)上的tmp目录的正确方法是什么?

谢谢

编辑:
我正在运行需要访问tmp文件的延迟作业方法.

EDIT2:
我在做什么:

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 => thumb_filename)

        # save path to the new thumbnail to database
        f.update_attributes(:file_url_thumb => "https://s3-us-west-1.amazonaws.com/bucket/#{filename}")
      end
    end

我有关于图像的数据库信息.这些图像存储在Amazon S3存储桶中.我需要为这些图像创建缩略图.因此,我将通过另一个图像,加载图像,暂时保存,然后调整大小,然后我将此缩略图上传到S3存储桶.

但是这个程序似乎不适用于Heroku,所以,我怎么能这样做(我的应用程序在Heroku上运行)?

解决方法

/ tmp是否包含在您的git仓库中?删除你的.slugignore?该目录可能在Heroku上不存在.

在写之前尝试在快速mkdir中折腾:

Dir.mkdir(File.join(Rails.root,'tmp'))

甚至在初始化器或其他东西……

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...