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
You should read file first from your application. And then make it available for download.
attachment = Attachment.find(params[:id])
data = open(attachment.doc.url).read
send_file data,
:filename => attachment.doc_file_name,
type: attachment.doc_content_type, stream: 'true',
:x_sendfile => true
You can also make it available like :
redirect_to attachment.doc.url
But this is not a right way to do so. Because you directly opening your resources to end user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With