Sha256: afd9cc0fc5b6de5656e196c468f00af13f1aebbc5b491090557e1b73d938f4da

Contents?: true

Size: 813 Bytes

Versions: 5

Compression:

Stored size: 813 Bytes

Contents

module Tessa
  class RackUploadProxy

    def call(env)
      params = env['rack.request.form_hash']
      upload = Tessa::Upload.create(
        name: params["name"],
        size: params["size"],
        mime_type: params["mime_type"],
      )

      env['rack.session'][:tessa_upload_asset_ids] ||= []
      env['rack.session'][:tessa_upload_asset_ids] << upload.asset_id

      response = {
        asset_id: upload.asset_id,
        upload_url: upload.upload_url,
        upload_method: upload.upload_method,
      }

      [200, {"Content-Type" => "application/json"}, [response.to_json]]
    rescue Tessa::RequestFailed
      [500, {"Content-Type" => "application/json"}, [{ "error" => "Failed to retreive upload URL" }.to_json]]
    end

    def self.call(*args)
      new.call(*args)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tessa-0.6.0 lib/tessa/rack_upload_proxy.rb
tessa-0.5.0 lib/tessa/rack_upload_proxy.rb
tessa-0.4.0 lib/tessa/rack_upload_proxy.rb
tessa-0.3.1 lib/tessa/rack_upload_proxy.rb
tessa-0.3.0 lib/tessa/rack_upload_proxy.rb