Hi I am trying to upload images directly to S3 using refile gem
project.rb looks like
class Project < ActiveRecord::Base
has_many :photos, :class_name => "Project::Photo", dependent: :destroy
accepts_attachments_for :photos
end
project/photo.rb
class Project::Photo < ActiveRecord::Base
belongs_to :project
attachment :file
attr_accessible :name, :address, :created_at, :project_id, :file
before_create :debugging_create
end
config/initializers/refile.rb
require "refile/s3"
aws = {
access_key_id: "xyz",
secret_access_key: "abc",
region: "sa-east-1",
bucket: "my-bucket",
}
Refile.cache = Refile::S3.new(prefix: "cache", **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)
Output from Refile.backends [Image 1]
Params on file upload looks like this for photos_files [Image 2]
Issues:
- Unable to fetch and save the key in database which is being saved into amazon S3. Different keys is shown in the Refile.backends.
- How to save a new file on update. Currently it overrides the existing file.