app/models/caboose/media.rb in caboose-cms-0.7.70 vs app/models/caboose/media.rb in caboose-cms-0.7.71

- old
+ new

@@ -22,11 +22,13 @@ attr_accessible :id, :media_category_id, :name, :original_name, :description, - :processed + :processed, + :image_content_type, + :file_content_type has_attached_file :sample #before_post_process :set_content_dispositon #def set_content_dispositon @@ -45,24 +47,28 @@ bucket = Caboose::uploads_bucket && Caboose::uploads_bucket.strip.length > 0 ? Caboose::uploads_bucket : "#{bucket}-uploads" key = "#{self.media_category_id}_#{self.original_name}" key = URI.encode(key.gsub(' ', '+')) uri = "http://#{bucket}.s3.amazonaws.com/#{key}" - - image_extensions = ['.jpg', '.jpeg', '.gif', '.png', '.tif'] - ext = File.extname(key).downcase - mimetype = Caboose::Mimetype.mimetype_for_extension(ext) - if image_extensions.include?(ext) + + content_type = self.image_content_type || self.file_content_type + + if is_image? self.image = URI.parse(uri) - self.image_content_type = mimetype if mimetype + self.image_content_type = content_type else self.file = URI.parse(uri) - self.file_content_type = mimetype if mimetype - end + self.file_content_type = content_type + end self.processed = true self.save - + + # Set the content-type metadata on S3 + if !is_image? + self.set_file_content_type(content_type) + end + # Remember when the last upload processing happened s = Caboose::Setting.where(:site_id => self.media_category.site_id, :name => 'last_upload_processed').first s = Caboose::Setting.create(:site_id => self.media_category.site_id, :name => 'last_upload_processed') if s.nil? s.value = DateTime.now.utc.strftime("%FT%T%z") s.save @@ -78,11 +84,12 @@ config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env] AWS.config({ :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] }) - bucket = config['bucket'] + s3 = AWS::S3.new + bucket = s3.buckets[config['bucket']] ext = File.extname(self.image_file_name)[1..-1] self.image.styles.each do |style| k = "media/#{self.id}_#{self.name}_#{style}.#{ext}" bucket.objects[k].copy_from(k, :content_type => content_type) # a copy needs to be done to change the content-type end @@ -92,12 +99,13 @@ config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env] AWS.config({ :access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key'] }) - bucket = config['bucket'] - ext = File.extname(self.image_file_name)[1..-1] - has_attached_file :file, :path => ':caboose_prefixmedia/:id_:media_name.:extension' + s3 = AWS::S3.new + bucket = s3.buckets[config['bucket']] + ext = File.extname(self.file_file_name)[1..-1] + # has_attached_file :file, :path => ':caboose_prefixmedia/:id_:media_name.:extension' k = "media/#{self.id}_#{self.name}.#{ext}" bucket.objects[k].copy_from(k, :content_type => content_type) # a copy needs to be done to change the content-type end def download_image_from_url(url)