开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜