开发者

Rails pdf file display

开发者 https://www.devze.com 2023-03-25 14:01 出处:网络
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 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

精彩评论

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

关注公众号