red-devil
red-devil

Reputation: 1103

Save image details on upload to amazon S3 with refile gem, Ruby on Rails

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]

Output from Refile.backends

Params on file upload looks like this for photos_files [Image 2]

Params on file upload looks like this for photos_files

Issues:

  1. Unable to fetch and save the key in database which is being saved into amazon S3. Different keys is shown in the Refile.backends.
  2. How to save a new file on update. Currently it overrides the existing file.

Upvotes: 2

Views: 267

Answers (0)

Related Questions