Project

General

Profile

Defect #3911 » uploading_attachment_file_with_jruby.patch

Patch v1 - Babar O'Cap, 2009-09-23 16:24

View differences:

app/controllers/application.rb
if attachments && attachments.is_a?(Hash)
attachments.each_value do |attachment|
file = attachment['file']
next unless file && file.size > 0
next unless file && (file.size > 0 || File.size(file) > 0)
a = Attachment.create(:container => obj,
:file => file,
:description => attachment['description'].to_s.strip,
app/models/attachment.rb
def file=(incoming_file)
unless incoming_file.nil?
@temp_file = incoming_file
if @temp_file.size > 0
if @temp_file.size > 0 || File.size(@temp_file) > 0
self.filename = sanitize_filename(@temp_file.original_filename)
self.disk_filename = Attachment.disk_filename(filename)
self.content_type = @temp_file.content_type.to_s.chomp
self.filesize = @temp_file.size
self.filesize = (@temp_file.size > 0)? @temp_file.size : File.size(@temp_file)
else
logger.debug("temp_file size is lower or equal to 0")
end
end
end
......
# Copies the temporary file to its final location
# and computes its MD5 hash
def before_save
if @temp_file && (@temp_file.size > 0)
if @temp_file && (@temp_file.size > 0 || File.size(@temp_file) > 0)
logger.debug("saving '#{self.diskfile}'")
md5 = Digest::MD5.new
File.open(diskfile, "wb") do |f|
(1-1/2)