Rails pdf file display
I am working on uploading/downloading files in Rails 3.x and storing the uploaded files in MySQL 开发者_JAVA百科db. Pdf and doc files are stored in Binary/Image i.e BLOB format.
I am facing problem in displaying the contents of pdf file on the browser.
Code for displaying pdf on browser (controller) :
@attachment = Attachment.find(params[:id])
send_data(@attachment.data,
:filename => @attachment.filename,
:type => @attachment.content_type,
:disposition => "inline")
Output : Either file is NOT displayed or it says" file is damaged, cannot be repaired"
Any suggestions ??
Thanks in advance !
hey try changing datatype of column in mysql from blob to longblob & following in view :
<% elsif (attachment.content_type==('application/pdf')) %>
<td> <embed src="<%=url_for(:action => 'pdfshow', :id => attachment.id) %>" width="80%" height='500'> </td>
精彩评论