Sha256: 091452dce4e1f50912eb9739cc0f6b548e65991464fa2aa73b5d01bdbbe9230d

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module S3Multipart
  class Upload < ::ActiveRecord::Base
    extend S3Multipart::TransferHelpers

    attr_accessible :key, :upload_id, :name, :location, :uploader
#before_create :validate_mime_types

    def self.create(params)
      response = initiate(params)
      super(key: response["key"], upload_id: response["upload_id"], name: response["name"], uploader: params["uploader"])
    end

    def execute_callback(stage, session)
      controller = deserialize(uploader)
      
      case stage
      when :begin
        controller.on_begin_callback.call(self, session)
      when :complete
        controller.on_complete_callback.call(self, session)
      end
    end

    private

      def validate_mime_types(upload)
        ext = upload.name.match(/\.([a-zA-Z0-9]+)$/)[1]
        controller = deserialize(upload.uploader)

        if !controller.file_types.include?(ext)
          return false
        end
      end

      def deserialize(uploader)
        S3Multipart::Uploader.deserialize(uploader)
      end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
s3_multipart-0.0.8 app/models/s3_multipart/upload.rb