Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 通过延迟作业将图像上载到heroku_Ruby On Rails_Heroku_Amazon S3_Paperclip - Fatal编程技术网

Ruby on rails 通过延迟作业将图像上载到heroku

Ruby on rails 通过延迟作业将图像上载到heroku,ruby-on-rails,heroku,amazon-s3,paperclip,Ruby On Rails,Heroku,Amazon S3,Paperclip,我正在尝试使用延迟作业将图像从Heroku上传到s3 bucket 但看起来heroku延迟的作业无法获得tmp映像路径。 请让我知道我做错了什么或更好的方法 这是我的控制器代码: if @post.save unless @post.post_type == 0 image_a = image_b = '' if item_image_params['0'][:item_type] == "A" image_a = item_image_pa

我正在尝试使用延迟作业将图像从Heroku上传到s3 bucket

但看起来heroku延迟的作业无法获得tmp映像路径。 请让我知道我做错了什么或更好的方法

这是我的控制器代码:

  if @post.save
    unless @post.post_type == 0
      image_a = image_b = ''
      if item_image_params['0'][:item_type] == "A"
        image_a = item_image_params['0'][:image]
        image_b = item_image_params['1'][:image]
      else
        image_a = item_image_params['1'][:image]
        image_b = item_image_params['0'][:image]
      end
      @post.delay.save_image(image_a.path, image_b.path)
    end
  end
我的型号代码:

  def save_image(image_a, image_b)
    items.each do |item|
      if item.item_type == "A"
        item.build_item_image.image = File.open(image_a)
      else
        item.build_item_image.image = File.open(image_b)
      end
    end
    if self.save
      File.delete(image_a) if File.exist?(image_a)
      File.delete(image_b) if File.exist?(image_b)
    end
  end
我在delayed中遇到了这个错误:

:save_image args: - /tmp/RackMultipart20150715-3-1qoy83r.jpeg - /tmp/RackMultipart20150715-3-if712h.jpeg 
 last_error:
  "No such file or directory - /tmp/RackMultipart20150715-3-if712h.jpeg\n/app/app/models/post.rb:35:in
第35行代码为:

 item.build_item_image.image = File.open(image_b)

Heroku dynos无法访问彼此的本地文件系统。如果我理解正确,您有一个web dyno正在写入其本地文件系统(/tmp),然后试图从另一个(工作者)dyno读取它

你最好直接上传到S3。我已经成功地用过了,或者你可以用别的东西,或者自己滚

直接上传到S3还有一个优点,即在上传过程中不会占用您的web动态,也不会导致超时。如果直接上传到heroku并花费比web dyno的超时时间更长的时间(因为文件太大或用户的连接太慢),那么上传就会失败


我看到你用
回形针
标记了这个问题。您可能会发现Heroku很有用,尽管它似乎没有使用直接上传到s3的首选方法。有一些用回形针直接上传到s3的示例代码。

如果我将tmp文件移动到我们的应用程序公用目录文件夹中会怎么样。可行吗?我的意思是,如果我使用延迟存储,它会节省一些用户时间吗?这仍然存在使用dyno本地存储的相同问题。本地存储与其他动态和临时存储隔离。如果您将文件移动到公共目录,它们仍然只能由接收它们的dyno使用,并且只能在该dyno的生命周期内使用。当您部署新版本、重新启动等时,它们将消失。