mardi 19 mai 2015

Uploading Images to S3 through Rails App on Heroku

I have been unable to upload images to S3 through my Rails application that is hosted on Heroku. I've been able to upload them to the system folder; however, because of Heroku's ephemeral file system this does not work.

Here's a list of things that I've tried:

None of these solutions have worked.

I've got the following configuration files in my Rails app:

config/initializers/paperclip.rb

Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

config/initializers/aws.rb

AWS.config(access_key_id:     ENV['actual-access-key'],
           secret_access_key: ENV['actual-secret-access-key'] )

S3_BUCKET = AWS::S3.new.buckets[ENV['actual-bucket-name']]

config/s3.yml

access_key_id: 'ActualAccessKey'    
secret_access_key: 'ActualSecretAccessKey'
bucket: 'actual-bucket-name'

config/environments/production.rb

  config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => ENV['actual-bucket-name'],
      :access_key_id => ENV['actual-access-key'],
      :secret_access_key => ENV['actual-secret-access-key']
    }
  }

Note: actual-bucket-name, actual-access-key, and actual-secret-access-key contain the correct information from my Amazon S3 account.

Here's my form:

= form_for(@project, multipart: true) do |f|
  - if @project.errors.any?
    #error_explanation
      h2
        = pluralize(@project.errors.count, "error")
        |  prohibited this project from being saved:
      ul
        - @project.errors.full_messages.each do |message|
          li
            = message
  .field
    = f.label :pictures
    br  
    = file_field_tag "images[]", type: :file, multiple: true 

Any ideas as to why I haven't been able to upload files to S3 through Heroku?

Aucun commentaire:

Enregistrer un commentaire