Send_file : downloaded file cannot be open after upload OK

I easily implemented the upload , using the ‘attachment_fu’ plugin…
I can see and open the uploaded files (a pdf file 60k and a jpeg images
28k)

now I try to implement the download action in my document_controller, I
wrote :

def download
@document = Document.find(params[:id])
send_file(@document.full_filename,
:filename => URI.encode(@document.filename),
:type => @document.content_type,
:encoding => ‘utf8’,
:disposition => ‘attachment’,
:stream => ‘true’,
:buffer_size => ‘4096’)
redirect_back_or_default(home_url)
end

I got back the downloaded files… but i always get back a 16k whatever
it’s pdf or jpeg, and when I try to open them, I got an error :

Failed to find PDF header: `%PDF’ not found. for the pdf file and
corrupted or not recognized…

what’s wrong in my send_file options

note : I am testing locally on localhost

On 27 Aug 2007, at 13:04, Kad K. wrote:

@document = Document.find(params[:id])
send_file(@document.full_filename,
 :filename     =>  URI.encode(@document.filename),
 :type         =>  @document.content_type,
 :encoding => 'utf8',
 :disposition  =>  'attachment',
 :stream    =>  'true',
 :buffer_size  =>  '4096')
  redirect_back_or_default(home_url)

end

Don’t redirect at the end of your for one. No new page will be
rendered anyway (the user will just get the download dialog).

Also don’t make things more complicated than they need to be:
def download
@document = Document.find(params[:id])
send_file(@document.full_filename,
:filename => @document.filename,
:type => @document.content_type,
:disposition => ‘attachment’)
end

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 27 Aug 2007, at 13:04, Kad K. wrote:

@document = Document.find(params[:id])
send_file(@document.full_filename,
 :filename     =>  URI.encode(@document.filename),
 :type         =>  @document.content_type,
 :encoding => 'utf8',
 :disposition  =>  'attachment',
 :stream    =>  'true',
 :buffer_size  =>  '4096')
  redirect_back_or_default(home_url)

end

Don’t redirect at the end of your for one. No new page will be
rendered anyway (the user will just get the download dialog).

Also don’t make things more complicated than they need to be:
def download
@document = Document.find(params[:id])
send_file(@document.full_filename,
:filename => @document.filename,
:type => @document.content_type,
:disposition => ‘attachment’)
end

Best regards

Peter De Berdt

Thanks Peter ! up and running well…

btw , are u from SA ? (because of the name…) if yes, be our guest for
the coming Rugby World Cup, otherwise sorry, u will not understand that
game… ;-))

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs