简体   繁体   English

带有重新归档的rails S3子文件夹

[英]rails S3 subfolders with refile

I have a rails 4 app. 我有一个Rails 4应用程序。 I'm trying to make a subfolder system on S3 for different refile uploaders. 我正在尝试在S3上为不同的重新上传文件者创建一个子文件夹系统。 I tried the code below but it didn't work out. 我尝试了下面的代码,但没有成功。 Nothing got uploaded to S3 nor got displayed in the app. 什么都没有上传到S3,也没有显示在应用程序中。

What did I miss? 我错过了什么?

The logs: 日志:

20:24:09 puma.1    | Started GET "/attachments/refile_caches_backend/presign?t=1459707849942.0" for ::1 at 2016-04-03 20:24:09 +0200
20:24:10 puma.1    | Refile::App: [2016-04-03 20:24:10 +0200] GET "/refile_caches_backend/presign?t=1459707849942.0" 404 29.7ms

refile.rb refile.rb

require "refile/s3"

aws = {
  access_key_id: ENV['AWS_ACCESS_KEY_ID'],
  secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
  region: "us-east-1",
  bucket: ENV['S3_BUCKET_NAME']
}

message_files = aws.merge({bucket: "message_files"})
product_files = aws.merge({bucket: "product_files"})
refile_caches = aws.merge({bucket: "refile_caches"})

Refile.backends["message_files_backend"] = Refile::S3.new(prefix: "store", **message_files)
Refile.backends["product_files_backend"] = Refile::S3.new(prefix: "store", **product_files)
Refile.backends["refile_caches_backend"] = Refile::S3.new(max_size: 5.megabytes, prefix: "cache", **refile_caches)
Refile.cdn_host = ENV['CLOUDFRONT_URL']

message.rb message.rb

class Message < ActiveRecord::Base
  attachment :message_attachment, store: 'message_files_backend', cache: 'refile_caches_backend' ,extension: ["pdf", "doc", "docx", "xls", "xlsx", "html", "png", "img", "jpg"]
end

I don't know why, but I couldn't configure the cache with Refile.backends , so I just left it as it was, since that part doesn't seem to be crucial. 我不知道为什么,但是我无法使用Refile.backends配置缓存,所以我只保留了它,因为那部分似乎并不关键。

For the storage the backend configuration works, files get uploaded to the desired subfolder. 对于存储,后端配置有效,文件被上载到所需的子文件夹。

Refile.backends["message_files_backend"] = Refile::S3.new(prefix: "store/message_files", **aws)
Refile.backends["product_files_backend"] = Refile::S3.new(prefix: "store/product_files", **aws)
Refile.cache = Refile::S3.new(max_size: 5.megabytes, prefix: "cache", **aws)

#in the model thanks to using the default cache it doesn't have to be defined
class Message < ActiveRecord::Base
  attachment :message_attachment, store: 'message_files_backend', extension: ["pdf", "doc", "docx", "xls", "xlsx", "html", "png", "img", "jpg"]
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM