Sha256: 0239bb0f8c78bbb9109df2ac95e5245e4603185c99f1c3d1a9204c8170df0f2f

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Uploadbox
  module ImgHelper
    def s3_policy
      Base64.encode64(policy_data.to_json).gsub("\n", "")
    end


    def s3_signature
      Base64.encode64(
        OpenSSL::HMAC.digest(
          OpenSSL::Digest::Digest.new('sha1'),
          CarrierWave::Uploader::Base.fog_credentials[:aws_access_key_id],
          s3_policy
        )
      ).gsub("\n", "")
    end

    def img(source, options={})
      if source.respond_to?(:url) and source.respond_to?(:width) and source.respond_to?(:height)
        image_tag(source.url, {width: source.width, height: source.height}.merge(options))
      else
        image_tag(source, options)
      end
    end

    private
      def policy_data
        {
          expiration: 10.hours.from_now.utc.iso8601,
          conditions: [
            ["starts-with", "$key", 'uploads/'],
            ["content-length-range", 0, 500.megabytes],
            ["starts-with","$content-type",""],
            {bucket: CarrierWave::Uploader::Base.fog_directory},
            {acl: 'public-read'}
          ]
        }
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uploadbox-0.0.23 app/helpers/uploadbox/img_helper.rb