Sha256: a6eacdb492ba3392e991b1a6cdc0e42d7d603c44497aab1a5e252fd3aaf71b68
Contents?: true
Size: 1.64 KB
Versions: 8
Compression:
Stored size: 1.64 KB
Contents
module RailsUploads module Storages class S3 cattr_accessor :config def initialize(default) if (Rails.env == 'test' and not default) env = 'test' elsif default env = 'production' else env = Rails.env end config = self.class.config[env] AWS.config access_key_id: config['access_key_id'], secret_access_key: config['secret_access_key'] @bucket = AWS::S3.new.buckets[config['bucket']] @tmp = {} end def exists?(path) object(path).exists? end def size(path) object(path).content_length end def url(path) base_url = Rails.application.config.uploads.base_url base_url.present? ? ::File.join(base_url, path) : object(path).public_url(secure: false) end def store(upload, path) @bucket.objects.create(path, Pathname.new(upload.path)).acl = :public_read end def delete(path) object(path).delete end def magick(source, output, upload) if @tmp[source].blank? if upload.present? @tmp[source] = upload.path else remote = Tempfile.new('s3') remote.binmode object(source).read { |chunk| remote.write(chunk) } remote.close remote.open @tmp[source] = remote.path end end tmp = Tempfile.new('s3') yield RailsUploads::Magick::Image.new(@tmp[source], tmp.path) store tmp, output end protected def object(path) @bucket.objects[path] end end end end
Version data entries
8 entries across 8 versions & 1 rubygems