Rails attachment_fu db_file upload issue

I’ve recently added attachment_fu to my applicatons, and it works
without reporting any errors. Works fine in :file_system mode, but
not in :db_file mode. It seems to upload only about 45 bytes of data
instead of the entire image, image download works fine when I manually
put the data in the database.

I’ve created an Icon model that has the following has_attachment
settings

has_attachment :content_type => :image,
:storage => :db_file,
:max_size => 1.megabyte,
:resize => ‘75x75>’,
:processor => ‘MiniMagick’

validates_as_attachment

I’ve removed the resize and processor statements and I’m fairly
confident that the issue is not related to image processing. And
again the upload works to storage type :file_system. My controller
create method looks like this:

def create
@icon = Icon.new(params[:icon])
if @icon.save
flash[:notice] = ‘Icon was successfully created.’
redirect_to :action => ‘show’, :id => @icon
else
render :action => :new
end
end

And my ‘new’ view looks like:

<%= error_messages_for :icon %>

<% form_for(:icon, :url => {:action => ‘create’},
:html => { :multipart => true }) do |f| -%>

Upload An Icon <%= f.file_field :uploaded_data %>

<%= submit_tag 'Create' %>

<% end -%>

Any suggestions would be greatly appreciated.

Thanks,
j

In your migrations for db_file use
t.column :binary, :limit => 500.megabyte

You can us whatever the limit you want to keep

That should fix it

Joshua,

Don’t know if you found the solution for this issue, but I thought I’d
throw in my thoughts just in case. I’ve been having the exact same
issue (corrupted uploads in the database with only 5 - 120 bytes, but
full functionality using file_system mode), and I came across the
following thread:

http://www.ruby-forum.com/topic/99870

A posting by ‘Adam’ near the end of the thread looks like this:


To get things working with S3 and windows, I changed:

  def temp_data
    if save_attachment?
      f = File.new( temp_path )
      f.binmode
      return f.read
    else
      return nil
    end
  end

(before, the method body was save_attachment? ?
File.read( temp_path ) :
nil )

It’s kind of ugly as it assumes attachments are binary, but it works
in
my situation.


I made this change and everything works properly now. Hooray!

~Mike