From fb6506e9d78ced1030210f5cbfd6fee3cccbc569 Mon Sep 17 00:00:00 2001 From: Jatin Jha Date: Thu, 10 Sep 2020 18:49:50 +0530 Subject: [PATCH] upload folder will be decided according to the extension name --- app/controllers/froala_controller.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/froala_controller.rb b/app/controllers/froala_controller.rb index 513c45d..4e06248 100644 --- a/app/controllers/froala_controller.rb +++ b/app/controllers/froala_controller.rb @@ -1,5 +1,7 @@ class FroalaController < ActionController::Base + VIDEO_EXT = [".mp4", ".webm", ".ogg"] + FILE_EXT = [".txt",".json",".html",".pdf",".doc"] # Index. def index options = { @@ -101,8 +103,18 @@ def upload_video # Access uploaded files. def access_file - if File.exists?(Rails.root.join('public', 'uploads', 'images', params[:name])) - File.open(Rails.root.join('public', 'uploads', 'images', params[:name]), 'rb') do |f| + ext = File.extname(params[:name]) + + if(VIDEO_EXT.include?(ext)) + fileUploadFolder = 'videos' + elsif(FILE_EXT.include?(ext)) + fileUploadFolder = 'files' + else + fileUploadFolder = 'images' + end + + if File.exists?(Rails.root.join('public', 'uploads', fileUploadFolder , params[:name])) + File.open(Rails.root.join('public', 'uploads', fileUploadFolder , params[:name]), 'rb') do |f| send_data f.read, :filename => ::File.basename(params[:name]), :disposition => "inline" end else