Send_file pdf problem


#1

Hi,

I am using send_file to allow users to download files from my website,
please see code beloe:

def download_document
send_file("#{RAILS_ROOT}/public/test_form.pdf",
:filename => “test.pdf”,
:type => ‘application/pdf’,
:disposition => ‘attachment’,
:streaming => ‘true’,
:buffer_size => ‘4096’)
end

If i leave disposition => “attachment” i get the following error when
trying to open the document:

“Adobe Reader could not open the file type …because it is either not
a supported file type or because the file has become damaged…”

Or if i change disposition => “inline” i get the following error
message:

File does not begin with ‘%PDF-’ "

Whats that all about??? I have the mime types set up correctly.

Can anyone help me?

JB


#2

This is the error from the log:

TypeError (can’t convert String into Integer):
/vendor/rails/actionpack/lib/action_controller/streaming.rb:75:in
sysread' /vendor/rails/actionpack/lib/action_controller/streaming.rb:75:insend_file’
/vendor/rails/actionpack/lib/action_controller/streaming.rb:71:in
open' /vendor/rails/actionpack/lib/action_controller/streaming.rb:71:insend_file’
/vendor/rails/actionpack/lib/action_controller/cgi_process.rb:183:in
call' /vendor/rails/actionpack/lib/action_controller/cgi_process.rb:183:inout

It says it is trying to open test-2.pdf where is the -2 coming from??


#3

Thanks Rich, this has me on the right track now.


#4

I am using send_file to allow users to download files from my
website, please see code beloe:

def download_document
send_file("#{RAILS_ROOT}/public/test_form.pdf",
:filename => “test.pdf”,
:type => ‘application/pdf’,
:disposition => ‘attachment’,
:streaming => ‘true’,
:buffer_size => ‘4096’)
end

Hello,

Which webserver? I spent quite a lot of time on this issue last year.

I finally installed Apache 1.3.36, 2.0.48, 2.0.49, 2.0.58, and 2.2.2
from source, the installed Suse 2.0.48, along with lighttpd 1.4.11 and
tested them all. As I recall, the problem stemmed mostly from the
2.0.48 distributed by Suse, and lighty. Also, the user had to have been
using IE6, and the Acrobat Reader setting had to be to open the PDF in
the same window as Explorer.

Here is the lighty config file fix:
$HTTP[“url”] =~ “.pdf$” {
server.range-requests = “disable”
}

Which disallows range requests. The drawback is that the user will have
to download the complete PDF file before they can view it, but it does
eliminate the problem.

I think there is more relevant data here:
http://www.samspublishing.com/articles/article.asp?p=26698&rl=1
http://www.squid-cache.org/mail-archive/squid-dev/199801/0006.html

Regards,

Rich D.


#5

For me it works fine for code:

file_path=c:/pdfs/file.pdf
send_file(file_path,
:filename => File.basename(file_path),
:type => ‘application/pdf’,
:disposition => ‘inline’,
:streaming => ‘true’,
:buffer_size => 4096) <-- I changed that.

But in fact I’m still in development stage and I haven’t tried it on
Apache server.

On 23 Kwi, 21:56, John B. removed_email_address@domain.invalid