Sha256: 8aba59303bf069dc2e2e28746ad7884fd70721c942dd0e32d8341ef3a0e75a41

Contents?: true

Size: 888 Bytes

Versions: 5

Compression:

Stored size: 888 Bytes

Contents

module Roroacms  

  module MediaHelper

    require "aws-sdk"

    BUCKET = Setting.get('aws_bucket_name')
   
    AWS.config(
        :access_key_id => Setting.get('aws_access_key_id'),
        :secret_access_key => Setting.get('aws_secret_access_key')
    )

    S3 = AWS::S3.new

    def upload_images(file, type, initial_folder = 'users')
        path = "#{BUCKET}/" + Setting.get("aws_folder") + "/" + initial_folder.to_s + "/" + type.to_s + "/" + file.original_filename
        begin
            obj = S3.buckets[BUCKET].objects["#{path}"].write(:file => file, :acl => :public_read)
            unauthenticated_url(obj)
        rescue => e
            logger.warn e.to_s
            return nil
        end
    end


    def unauthenticated_url(obj = nil)
      obj = obj.url_for(:read).to_s.split("?")[0] if !obj.nil?
      obj
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roroacms-0.0.6.4 app/helpers/roroacms/media_helper.rb
roroacms-0.0.6.2 app/helpers/roroacms/media_helper.rb
roroacms-0.0.6.1 app/helpers/roroacms/media_helper.rb
roroacms-0.0.6 app/helpers/roroacms/media_helper.rb
roroacms-0.0.5 app/helpers/roroacms/media_helper.rb