Downloading files from database

hallo everybody,

i got a weird problem with some code i wrote. it’s a function to save
files to the database and later download them again.

the weird thing is, that on my home machine everything is working
correctly, but on my webserver some (not all, only some!) files get
corrupted when i try to download them. that means my browser shows me a
filesize of e.g. 1,3mb but can only download 1,1mb and then aborts the
download. --> the file gets corrupted!

here is my code:


  def new
    @download = Download.new
    if request.post?
      @download = Download.new
      @download.date = Time.now
      @download.attributes = @params[:download]
      unless @params[:chosen_file] == ""
        @download.filename = 
@params[:chosen_file].original_filename.gsub(/[^a-zA-Z0-9.]/, '_')
        @download.content = @params[:chosen_file].content_type
        @download.file = @params[:chosen_file].read
        @params[:download].delete(:chosen_file)
      end
      if @download.save
        flash[:notice] = 'Download wurde erfolgreich gespeichert.'
        redirect_to(:action => 'list')
      end
    end
  end

  def get
    @download = Download.find(@params[:id])
    send_data @download.file, :filename => @download.filename, :content 
=> @download.content
  end

has anybody got an idea what could be wrong with that? if you need more
information, just tell me what you need to know.

i already checked if filesize could be a problem, but as i’am able to
upload even bigger files, everything seems to be ok. i’m stuck…

thanks in advance for any suggestion
n0ne

What deployment architecture are you using ? Apache 1.3.x + mod fast cgi
defaults to timing out actions after 30 seconds I believe, could it be
something like that ?

Fred

has anybody got an idea what could be wrong with that? if you need more

information, just tell me what you need to know.

i already checked if filesize could be a problem, but as i’am able to
upload even bigger files, everything seems to be ok. i’m stuck…

thanks in advance for any suggestion
n0ne

Look for any differences in the environment. Are you using the same
brower?
Is it the same version etc? Maybe you are not setting the content type
in
your code.

Bala P. wrote:

Look for any differences in the environment. Are you using the same
brower?
Is it the same version etc? Maybe you are not setting the content type
in
your code.

i’m using the same browser. even tried it with different ones (opera,
firefox, konqueror, internetexplorer).

and i think i set the content type correctly.

n0ne wrote:

@download.content = @params[:chosen_file].content_type

otherwise the rest of the downloads would not be working correctly.
apparently this error only occurrs with some files. it can be reproduced
with these files, but it won’t happen to others.

any other ideas anyone?
could it be a problem with the webserver?

Frederick C. wrote:

What deployment architecture are you using ? Apache 1.3.x + mod fast cgi
defaults to timing out actions after 30 seconds I believe, could it be
something like that ?

i’m currently using

Debian Sarge
Rails 1.1.4
Litespeed 2.2
MySQL 4.1.11

but nevertheless i don’t hink it could be some timeout, because the
download starts and is active for some time, stops (=fails) and cannot
be resumed to complete the file. of course i can restart it but it would
crash at the same point every time.
on the other hand i am able to download bigger files, too. while the pdf
i mentioned (1.3mb) stops at 1.1mb, other files (even other pdf’s) that
have a filesize bigger than that (even > 10mb) are working fine.

When faced with problems with many possible directions, you must prod
the environment - using the results of the prod to indicate the next
area for inspection.

In my opinion, you should first determine whether its a server or
client issue.

To test this I’d write a functional test - download many different
files many times. The results of this test will suggest where to look
next. (a browser issue, or server, or potentially a specific file issue)

This approach enables your debugging by simplifying the environment.

and then you’ll find Sherlock Holmes to be especially useful in
determining your next course of action:
“that when you have eliminated the impossible, whatever remains,
however improbable, must be the truth”
Good luck.
Jodi

The issue is resolved now.
The developers from litespeed helped in finding a configuration option
that had to be adjust in order to make this work again.

Feurio

Hello,

we did narrow the problem area:

  1. We could save the problem files via console and open it them. The
    file contents were ok. -> So it seems not to be the database.
  2. We started the application with webbrick in prod mode. Everything
    worked. All downloaded files are ok. -> So it seems the ruby code for
    file up- and download is OK, too.

This leaves the webserver for me. We use Litespeed 2.2 and tried to
post the topic into the support forum of Litespeed Ltd., but I was not
able to do it, because I couldn´t register for the forum.

Feurio
I hope someone else from the rails list can help and has some tips or
advices.