Sha256: 1998e7dcdb6dc28b24381cfb1bdd190660ad9819484bbc0b9c5a0a27fec892c4

Contents?: true

Size: 1.01 KB

Versions: 36

Compression:

Stored size: 1.01 KB

Contents

module MobileWorkflow
  module S3Storable
    if Object.const_defined?("Aws::S3")
      extend ActiveSupport::Concern
      
      def binary_urls(object)
        return unless params["binaries"]
    
        params["binaries"].collect do |binary|
          extension = binary["mimetype"].split('/')[1] # i.e. image/jpg --> image, video/mp4 --> video
      
          {
            "identifier" => binary["identifier"],
            "url" => presigned_url("#{object.class.name.underscore}/#{object.id}/#{binary["identifier"]}.#{extension}"),
            "method" => "PUT"
          }
        end
      end
  
      private
      def presigned_url(key)
        presigner.presigned_url(:put_object, bucket: ENV['AWS_BUCKET_NAME'], key: key, metadata: {})
      end
  
      def presigner
        Aws::S3::Presigner.new(client: s3_client)
      end
  
      def s3_client
        Aws::S3::Client.new(region: ENV['AWS_REGION'], access_key_id: ENV['AWS_ACCESS_ID'], secret_access_key: ENV['AWS_SECRET_KEY'])
      end
      
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
mobile_workflow-0.6.21 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.20 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.19 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.18 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.17 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.16 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.15 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.14 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.13 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.12 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.11 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.10 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.9 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.8 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.7 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.6 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.4 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.3 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.2 app/controllers/concerns/mobile_workflow/s3_storable.rb
mobile_workflow-0.6.1 app/controllers/concerns/mobile_workflow/s3_storable.rb