Sha256: 18309ab6226f136ada05628f59dd232847311b1957bf5159d8954fe668346289

Contents?: true

Size: 927 Bytes

Versions: 4

Compression:

Stored size: 927 Bytes

Contents

module CarrierWave
  module Storage
    class UcloudFile < CarrierWave::SanitizedFile
      attr_reader :path, :bucket

      def initialize(uploader, base, path)
        @uploader = uploader
        @path     = path
        @base     = base
        @bucket   = ::CarrierWave::Ucloud::Bucket.new(uploader)
      end

      def read
        response = bucket.get(path)
        @headers = response.headers.deep_transform_keys { |k| k.underscore.to_sym rescue key }
        response.body
      end

      def delete
        bucket.delete(path)
      end

      def url
        bucket.url(path)
      end

      def store(file, headers = {})
        bucket.put(path, file, headers)
      end

      def content_type
        headers[:content_type]
      end

      def content_type=(new_content_type)
        headers[:content_type] = new_content_type
      end

      def headers
        @headers ||= {}
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
carrierwave_ucloud-0.2.2 lib/carrierwave/storage/ucloud_file.rb
carrierwave_ucloud-0.2.1 lib/carrierwave/storage/ucloud_file.rb
carrierwave_ucloud-0.1.4 lib/carrierwave/storage/ucloud_file.rb
carrierwave_ucloud-0.1.3 lib/carrierwave/storage/ucloud_file.rb