Attachment_fu strange behaviour with file uploading

Hi,
thr’s a strange behavior with attachment_fu. when i upload a file,
sometimes it gets uploaded without prb/error msg and sometimes the same
file gives the error as size error msg. particularly, when i upload the
next file immediately after another. can anybody help me in this? thanks
in advance…

this is my mugshots model:-
class Mugshot < ActiveRecord::Base
has_attachment :content_type => [‘application/vnd.ms-excel’],
:storage => :file_system,
:max_size => 5.megabytes,
:path_prefix=>‘public/temp_files’

validates_as_attachment

def validate
errors.add_to_base(“You must choose a file to upload”) unless
self.filename
unless self.filename == nil
# Images should only be GIF, JPEG, or PNG
[:content_type].each do |attr_name|
enum = attachment_options[attr_name]
unless enum.nil? || enum.include?(send(attr_name))
errors.add_to_base(“You can only upload .xls file”)
end
end
# Images should be less than 5 MB
[:size].each do |attr_name|
enum = attachment_options[attr_name]
unless enum.nil? || enum.include?(send(attr_name))
errors.add_to_base(“file size should be smaller than 5 MB in
size”)
end
end
end
end
end

-Dhaval

I prefer to hack attachment_fu.rb in vendor/plugin/attachment_fu/lib
than make def validate in model. But here’s my correction for you :

class Mugshot < ActiveRecord::Base
has_attachment :content_type => [‘application/vnd.ms-excel’],
:storage => :file_system,
:size => 0.megabyte…5.megabytes,
:path_prefix=>‘public/temp_files’
validates_as_attachment

end

NOW, go to {RAILS_ROOT}\vendor\plugins\attachment_fu\attachment_fu.rb

in line 405 :

def attachment_attributes_valid?
[:size, :content_type].each do |attr_name|
enum = attachment_options[attr_name]
errors.add attr_name, ActiveRecord::Errors.add_to_base(“You can only
upload .xls file”)unless enum.nil? || enum.include?(send(attr_name))
end
end

and refresh your server. What do you think?

Reinhart
http://teapoci.blogspot.com

hi Reinhart,
hey, that worked!!! though “errors.add attr_name,
ActiveRecord::Errors.add_to_base(“You can only upload .xls file”)unless
enum.nil? || enum.include?(send(attr_name))” gave me NoMethod error, so
i kept the default line back. that gave me default error msg for wrong
upload. but that worked.
and even if i put “:size => 0.megabyte…5.megabytes,” line in my
code, that also worked fine :slight_smile:
now i could upload the files continuously… without error :smiley:

Thanks a ton Reinhart

-Dhaval

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs