Monday, June 23, 2008

File upload with attachment_fu

Attachment_fu is a great plug-in to upload a file. I used Mike Clark's blog as an example. By default, it gives the following validation message:
Content type can’t be blank
Content type is not included in the list
Size can’t be blank
Size is not included in the list
Filename can’t be blank

To get better validation message, either reopen attachment_fu.rb or do your own validation in your model. The following blog explains it nicely.

If you are using MySQL, you may want to increase max_allowed_packet size in “my.cnf”. The default size is apparently 1M. If you don't change this and upload a file larger than 1 M, you will get “ActiveRecord::StatementInvalid: Mysql::Error: #08S01Got a packet bigger than ‘max_allowed_packet’ bytes: INSERT INTO...

No comments: