#13 new

document files are truncated

Reported by redster | August 20th, 2007 @ 11:40 PM


I am having real troubles uploading documents into the database correctly. The aim is to be able to upload PDF, MS Word and Plain text files and store them in the database.

Given my problems it may be needless to say, I am using this on Windows and unfortunately, it looks like the site will be deployed with IIS (yuck!).

The data BLOB size for any of the uploaded documents in the db_files table is showing the incorrect size (i.e. only a part of the file seems to be uploaded) whereas the associated model shows the correct filesize.

Smaller text files and some smaller Word documents (less than 50K) are uploaded correctly whereas larger files seem truncated. This results in a corrupted file message for PDFs and for MS Word, the usual MS Office magic of trying to install some extra bits of software!

There is no particular size boundary at which this happens. I uploaded a certain 48K Word document with no problems whereas another 33K Word document doesn't make it (only 15K of it is stored in the BLOB).

I got the plugin working (insofar as it does) after applying the sleep x workaround for windows.

I have attempted the other fixes such as modifying tempfile.rb, and the various changes suggested within attachment_fu.rb but to no avail.

My code was simple enough (thanks to wonderful resources out there esp. Mike Clark's)

In the document model:

class Document < ActiveRecord::Base
  has_attachment :content_type => ['application/pdf', 'application/msword', 'text/plain'],
                 :max_size => 2.megabytes
  belongs_to :project
  has_many :topics

In the controller:

  def documentupload
    sleep 1 #this is here 'cause windows doesn't handle files well
    @document = Document.new(params[:document])
    unless @document.save
      flash[:notice] = 'document could not be saved'
    redirect_to :action => 'show', :permalink => @project.permalink

In the view:

<%= error_messages_for :document %>
<% form_for(:document, :url => { :action => 'documentupload', :id => @project.id}, 
							:html => { :multipart => true }) do |f| %>
	<%= f.file_field :uploaded_data %>
	<%= submit_tag 'Upload' %>
<% end %>

All the examples out there only talk about image files; hopefully, someone has implemented this for the file types I'm attempting here.

Thank you

Comments and changes to this ticket

  • caffeinefueled

    caffeinefueled October 19th, 2007 @ 11:37 AM

    I'm having the same problem but for images. I found a post that mentioned specifying a :limit on the binary data column which I tried but it didn't fix the issue of the images/thumbnails being truncated.

    If I use file system storage it works fine but using :db_file there seems to be an issue. I'm also on windows so perhaps its a platform issue... I'll try to test it out on a linux machine at some point and report back.

  • redster

    redster October 19th, 2007 @ 06:11 PM

    Hi Josh,

    I tried various things such as setting the database max packet size (I'm using MySQL), etc, but had no luck. Can't remember everything I tried because its been a while now but I remember even changing some ruby files (based on some suggestions I found on the World Wide).

    Anywho, one day, I switched to acts_as_attachment and everything just worked!

    So, that is my recommendation to all of you out there who have run into troubles with attachment_fu. Have nothing against attachment_fu (I trieddesperately to get it going) but I wasted far too much time getting file uploads working and life is too short to be doing that!



Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket