Use Google Docs Viewer to open document from rails app (paperclup, cloudfiles)

孤人 提交于 2019-12-23 19:51:59

问题


In our rails app we use paperclip to save files to rackspace cloudfiles. We want to allow users to VIEW the files without needing to download them and use a program on their computer. We have found https://docs.google.com/viewer which looks good for the job

We have the following method in the controller:

  def view
    att = Attachment.find(params[:id])      
    redirect_to "http://docs.google.com/viewer?url=#{CGI.escape(att.file.expiring_url((Time.now + 60.seconds)).gsub(/^http:/, "https:"))}" 
  end  

This generates the following url:

https://drive.google.com/viewerng/viewer?url=https://snet-storage101.syd2.clouddrive.com/v1/MossoCloudFS_4a360775-1b68-41f9-884f-e62e7567af25/container//attachments/files/000/003/488/original/AK-_Time_Recording.pdf?temp_url_sig%3Dd36797290b85f2dcd752xxxxxxe6a08951ad%26temp_url_expires%3D14xxxxx7408&u=0

The google docs viewer then tells us:

  • Apologies, there is no preview available.

I suspect it has to do with the "temp_url_sig" and "temp_url_expires" parameters that are appended to the pdf file url.

Any ideas how we can get this to work?

来源:https://stackoverflow.com/questions/27188687/use-google-docs-viewer-to-open-document-from-rails-app-paperclup-cloudfiles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!