Project

General

Profile

Defect #33752 » file_size.diff

Karel Pičman, 2020-07-21 09:37

View differences:

app/models/attachment.rb (working copy)
if @temp_file.respond_to?(:content_type)
self.content_type = @temp_file.content_type.to_s.chomp
end
self.filesize = @temp_file.size
end
end
......
if @temp_file
self.disk_directory = target_directory
self.disk_filename = Attachment.disk_filename(filename, disk_directory)
logger.info("Saving attachment '#{self.diskfile}' (#{@temp_file.size} bytes)") if logger
logger.info("Saving attachment '#{self.diskfile}'") if logger
path = File.dirname(diskfile)
unless File.directory?(path)
FileUtils.mkdir_p(path)
end
sha = Digest::SHA256.new
self.filesize = 0
File.open(diskfile, "wb") do |f|
if @temp_file.respond_to?(:read)
buffer = ""
......
f.write(@temp_file)
sha.update(@temp_file)
end
self.filesize = f.size
end
self.digest = sha.hexdigest
end
(3-3/5)