小编Din*_*esh的帖子

如何使用paperclip-googledrive从谷歌驱动器下载文件?

我已经在谷歌驱动器上完成文件上传,但在下载时遇到错误:

ActionController::MissingFile: Cannot read file original_22_Wages372-817339(wages).pdf
Run Code Online (Sandbox Code Playgroud)

我认为它没有得到谷歌驱动器路径.

附件模型:

has_attached_file :doc, 
  storage: :google_drive,
  google_drive_credentials: "#{Rails.root}/config/google_drive.yml",
  google_drive_options: {
    public_folder_id: '0BwCp_aK6VhiaQmh5TG9Qbm0zcDQ',
    path: proc { |style| "#{style}_#{id}_#{doc.original_filename}" }
  }
Run Code Online (Sandbox Code Playgroud)

控制器:

 attachment = Attachment.find(params[:id])      
 send_file attachment.doc.path(:original), 
   filename: attachment.doc_file_name, 
   type: attachment.doc_content_type, 
   stream: 'true', 
   x_sendfile: true
Run Code Online (Sandbox Code Playgroud)

提前致谢

ruby ruby-on-rails google-drive-api ruby-on-rails-4

5
推荐指数
1
解决办法
933
查看次数