Send_data

I want to display a pdf on my browser bu using send_data(File.read(FILE_PATH + FILE_NAME), :type => 'application/pdf',:disposition => 'inline', :filename => FILE_NAME)

But nothing happens. Do you know why ?

Serving it via AJAX or a normal request? Files always need to be served as a normal request. Otherwise you should make sure that the PDF as well as the path is valid.

If it isn’t one of these two, you’ll have to dig in deeper yourself and provide the list with more information.

Best regards

Peter De Berdt

Peter De Berdt wrote:

It seems to be a common problem with xdp files, which are not PDF files btw and should not be served as application/pdf, but as application/vnd.adobe.xdp+xml

But even then, the browser plugins can’t seem to handle it anyway, as you can see at Adobe forums: http://forums.adobe.com/thread/332614

Best regards

Peter De Berdt

what the hell are u doing, if u have file, u can simplify get link to user, for it

it will be more faster than use rails, and more native for user

Best Regards, dieinzige

What if the OP needs users to be logged in to view files? Or complete some other approval process. Not much sense having them accessible from the public directory in that instance, which would allow people to just bypass the security.

Mamadou Touré wrote: [...]

I'm having the file displayed now, but the other issue that I'm facing now is : I have several files to open, I put them in an array that I loop through, but only the last file is opened:

What's wrong ?

arr.each do |form|       file_name = form + "-" + vue.inte_no.to_s + "-" + vue.poas_id.to_s + "-" + vue.prch_id.to_s + ".xdp"          send_file(path_pdf_cpy + file_name,:type => 'application/pdf' , :disposition => 'attachment', :filename => file_name)    end

You can't send multiple files in response to one request. Do you want to join the pages of the PDF files into one long file?

Best,

Marnen Laibow-Koser wrote:

Mamadou Touré wrote: [...]

I'm having the file displayed now, but the other issue that I'm facing now is : I have several files to open, I put them in an array that I loop through, but only the last file is opened:

What's wrong ?

arr.each do |form|       file_name = form + "-" + vue.inte_no.to_s + "-" + vue.poas_id.to_s + "-" + vue.prch_id.to_s + ".xdp"          send_file(path_pdf_cpy + file_name,:type => 'application/pdf' , :disposition => 'attachment', :filename => file_name)    end

You can't send multiple files in response to one request. Do you want to join the pages of the PDF files into one long file?

Best, --

Thanks Marnen,

Unfortunately I have to hav each file on its own, I must not merge them in on single file. Is there a way to simulate several requests in order to loop through the array ?

Mamadou Touré wrote: [...]

Thanks Marnen,

Unfortunately I have to hav each file on its own, I must not merge them in on single file. Is there a way to simulate several requests in order to loop through the array ?

Even if there were, the browser would not be able to understand it. You could use several Ajax requests, but if I were your user, I'd be annoyed that your website was randomly downloading files without my consent. Why can't you just provide several download links for the files? Or create a zip or tar archive?

Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org

Jeremy wrote:

Hi everyone, I have to say that I am very pleased that I have received such great responses! I kept expecting that I would get the cold shoulder but instead I got real answers. I feel I have a solid direction and don't feel like I'm blindly trying to figure this stuff out. So please accept my sincerest thank you to all of you for helping me out!

Bob, I decided to go ahead and buy the book regardless if it's outdated :slight_smile: I kinda figured the way deployment is done couldn't have changed too much.

It probably has. I don't think Passenger was in wide use at the time, and it's now probably the most common choice for deployment.

Peter, Thank you, I appreciate your contribution as well. Although, it was a little over my head when you started talking "mercurial repositories" but I'm sure I'll understand what that means sometime in the near future.

Mercurial is a version control system -- though it's not in all that wide use in the Rails community. I think most Rails developers use Git. Which version control system are you using?

(Hint: if the answer is "none", fix that *today* by installing Git. There is no excuse whatsoever for neglecting version control.)

Also, check out Heroku for very easy Rails deployment.

Best,

Mamadou Touré wrote: [...]

Thanks Marnen,

Unfortunately I have to hav each file on its own, I must not merge them in on single file. Is there a way to simulate several requests in order to loop through the array ?

Even if there were, the browser would not be able to understand it. You could use several Ajax requests, but if I were your user, I'd be annoyed that your website was randomly downloading files without my consent. Why can't you just provide several download links for the files? Or create a zip or tar archive?

Find a command line utility for your server OS that will do that for you: http://www.google.be/search?q=command+line+pdf+xdp

Then just run the necessary command line instruction from your Rails app.

Best regards

Peter De Berdt

Peter De Berdt wrote: