Din*_*esh 5 ruby ruby-on-rails google-drive-api ruby-on-rails-4
我已经在谷歌驱动器上完成文件上传,但在下载时遇到错误:
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)
提前致谢
小智 1
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
933 次 |
| 最近记录: |