如何在rails中检查excel表和pdf文件大小?

时间:2015-08-14 11:43:56

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2

这是我的代码 -

file_name = "#{downloaded_file_name}_#{Time.now.strftime("%Y%m%d%H%M%S")}.pdf"

result, pdf_report = ReportFullStores.get_order_receipts(customer, input_data)
#call method
schedule_report.generate_schedule_report(file_name, pdf_report)

#here before sending the file into mailer I want to check the file size.

# If file size is greater than 20 mb
  #code here  
# else
  #code here
#end

- >这是将文件保存到文件夹中的方法,我需要读取此文件夹下的文件大小。

#save file in public/scheduled_reports folder xls / pdf or both
def generate_schedule_report(file_name, report_data)
  #then save file to public folder
  save_path = Rails.root.join('public/scheduled_reports',file_name)
  File.open(save_path, 'wb') do |file|
    file << report_data
  end
end

任何帮助将不胜感激。 谢谢。

0 个答案:

没有答案