如何使用paperclip

编程入门 行业动态 更新时间:2024-10-27 02:21:26
如何使用paperclip-googledrive从谷歌驱动器下载文件?(How to download file from google drive using paperclip-googledrive?)

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

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}" } }

控制器:

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

提前致谢

I have done file uploading on google drive but at the time of downloading got error:

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

I think it didn't get google drive path.

Attachment model:

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

Thanks in advance

最满意答案

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

Dinesh, try the below code it will solve your problem.

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

更多推荐

本文发布于:2023-07-09 14:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1087135.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   paperclip

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!