Download manager? anyone?

Hello all,

i have been searching for some time now on how to upload files and then
display them to be downloaded, haven’t had any luck. it seems all the
documentation is for uploading and displaying pictures. is this the same
thing? i’m lost… any help would be greatly appreciated.

Jon

On 5/22/06, Jon Mr [email protected] wrote:

Hello all,

i have been searching for some time now on how to upload files and then
display them to be downloaded, haven’t had any luck. it seems all the
documentation is for uploading and displaying pictures. is this the same
thing? i’m lost… any help would be greatly appreciated.

Hi Jon,

Assuming you already uploaded the data to your database, you can do
something like this to show it:

Show a binary file

def download_file
@filedata = FileData.find(@params[:id])

  @response.headers['Pragma'] = ' '
  @response.headers['Cache-Control'] = ' '
  @response.headers['Content-type'] = @filedata.mime_type
  @response.headers['Accept-Ranges'] = 'bytes'
  @response.headers['Content-Length'] = @filedata.data.length
  @response.headers['Content-Transfer-Encoding'] = 'binary'
  @response.headers['Content-Description'] = 'File Transfer'
  # Remove the following comment if you want to force downloading

instead of viewing inline

@response.headers[‘Content-Disposition’] = "attachment;

filename=#{@filedata.filename}"
render_text @filedata.data
end


Sincerely,

Frodo L.

instead of hand coding it, you can also use send_data or send_file:

ActionController::Streaming

Sincerely,

Frodo L.

wow, that’s sweet. Thanks for the tip Ezra.

Michael

Hey thanks guys! (and gals). That’s why i love this stuff, it’s the
community.

Jon

On May 22, 2006, at 2:40 PM, Jon Mr wrote:

Jon-

Here is an open source rails app that is a file upload and download

manager. I think you could learn all you are looking for by browsing
the source.

http://boxroom.rubyforge.org/

Cheers-
-Ezra