On 5/22/06, Jon Mr <jon.druse@gmail.com> 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 Larik