带有多个服务器的回形针

时间:2013-07-31 12:02:38

标签: ruby-on-rails paperclip delayed-job

我们最近扩展了一个使用多个负载均衡服务器的应用程序,我对Paperclip附件的处理有疑问,更具体地说,是延迟上传到S3

以下是该方案:

  • iPhone应用程序会向网络应用添加新数据,包括照片上传。
  • 出于性能原因,照片首先存储在本地
  • 我们使用delayed_job处理并将文件上传到S3

以下是相关代码:

has_attached_file :local

has_attached_file :remote, :styles =>{:thumb =>'100x100'},
                           :path => ":class/photos/:id_partition/:style.:extension",
                           :s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
                           :storage => :s3

after_save :update_remote

def photo
  remote_file_name ? remote : local
end

def photo=(attachment)
  local = attachment
end

def update_remote
  unless self.remote_file_name
    if self.local.exists?
      self.remote = self.local
      self.local = nil
      self.save
    end
  end
end

handle_asynchronously :update_remote

我的问题是,如何将其扩展到多个应用服务器?本地文件只存在于其中一个文件中,由于延迟,我不愿意直接上传到S3。

1 个答案:

答案 0 :(得分:0)

它没有准确回答这个问题,但我转而使用数据库作为“本地”附件(在转移到S3之前)代替文件系统,这解决了问题

相关问题