我已经完成了在Google驱动器上的文件上传,但是在下载时出现了错误:

ActionController::MissingFile: Cannot read file original_22_Wages372-817339(wages).pdf

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

附件型号:
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}" }
  }

Controller :
 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

提前致谢

最佳答案

Dinesh,请尝试以下代码,它将解决您的问题。

    attachment = Attachment.find(params[:id])
    data = attachment.doc.url(:original)
    data = open(attachment.doc.url(:original))

    send_file data, filename: attachment.doc_file_name,
      type: attachment.doc_content_type

关于ruby-on-rails - 如何使用paperclip-googledrive从Google驱动器下载文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26407639/

10-14 05:01