如何使用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).pdfI 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: trueThanks 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_typeDinesh, 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更多推荐
发布评论