Forum: Ruby on Rails send_file pdf problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2007-04-23 14:53
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
0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2007-04-23 14:56
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:in
`send_file'
    /vendor/rails/actionpack/lib/action_controller/streaming.rb:71:in
`open'
    /vendor/rails/actionpack/lib/action_controller/streaming.rb:71:in
`send_file'
    /vendor/rails/actionpack/lib/action_controller/cgi_process.rb:183:in
`call'
    /vendor/rails/actionpack/lib/action_controller/cgi_process.rb:183:in
`out

It says it is trying to open test-2.pdf where is the -2 coming from??
Da8f30efea70c7c865790820df7679b6?d=identicon&s=25 Duzenbury, Rich (Guest)
on 2007-04-23 16:56
(Received via mailing list)
> 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...
http://www.squid-cache.org/mail-archive/squid-dev/...

Regards,

Rich Duzenbury
0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2007-04-23 19:44
Thanks Rich, this has me on the right track now.
1ca5a9ef6be05c1ccc4cdc631162bc1e?d=identicon&s=25 Zirael (Guest)
on 2007-05-10 04:02
(Received via mailing list)
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 Butler <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.