Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
kill external file.
  • Loading branch information
cbeer committed Mar 4, 2013
1 parent c32bef5 commit 9aa4f91
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions app/models/generic_file.rb
Expand Up @@ -8,42 +8,11 @@ class GenericFile < ActiveFedora::Base
has_metadata 'descMetadata', :type => MediaAnnotationDatastream
has_file_datastream :name => "content", :type => FileContentDatastream, :control_group=>'E'

# Overridden to write the file into the external store instead of a datastream
def add_file(file, dsid, file_name)
return add_external_file(file, dsid, file_name) if dsid == 'content'
super
end

def add_external_file(file, dsid, file_name)
path = File.join(directory, file_name)
if file.respond_to? :read
File.open(path, 'wb') do |f|
f.write file.read
end
else
# it's a filename.
FileUtils.move(file, path)
end

content.dsLocation = URI.escape("file://#{path}")
content.mimeType = MIME::Types.type_for(path).first.content_type
set_title_and_label( file_name, :only_if_blank=>true )
save!
end

# Overridden to load the original image from an external datastream
def load_image_transformer
Magick::ImageList.new(content.filename)
end

def directory
dir_parts = noid.scan(/.{1,2}/)
dir = File.join(Rails.configuration.external_store_base, dir_parts)
puts "Making #{dir}"
FileUtils.mkdir_p(dir) unless Dir.exists?(dir)
dir
end

def log_events
TrackingEvent.where(pid: pid)
end
Expand Down

0 comments on commit 9aa4f91

Please sign in to comment.