Sha256: c3bc358251161ecbb2be77810ae8ddf2096aa7552469fcf6654369593e960fd7

Contents?: true

Size: 862 Bytes

Versions: 1

Compression:

Stored size: 862 Bytes

Contents

class ApiController < ActionController::API
  def current_user
    nil
  end
  
  def binary_urls(object)
    return unless params["binaries"]
    
    params["binaries"].collect do |binary|
      property = binary["identifier"].split('/')[0] # i.e. image/jpg --> image, video/mp4 --> video
      
      {
        "identifier" => binary["identifier"],
        "url" => presigned_url("#{object.class.name.underscore}/#{object.id}/#{property}"),
        "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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mobile_workflow_cli-0.1.4 templates/api_controller.rb