how to download zip folder in ruby on rails? -
i have download zip file in tmp folder have downloaded zip file not downloaded zip file. code type=>
=> download folder
def download_folder @patient_id = params[:patient_id] @photovideos = photovideo.where('patient_id = ?', user.encrypt(@patient_id)) @time_filename = time.now.strftime("%y%m%d%h%m%s").to_s << ".zip" tmp_filename = "#{rails.root}/tmp/"+ @time_filename zip::file.open(tmp_filename, zip::file::create) |z| @photovideos.each |photovideo| item = user.decrypt(photovideo[:patient_file]) file = "#{rails.root}/public/patients/#{@patient_id}/"+ item if file.exists?(file) t = file.open(file) z.add(item, t) end end end file.chmod(0777, tmp_filename) send_file tmp_filename, :type=>"application/zip", :x_sendfile=>true tmp_filename.delete() #to remove tempfile render json: { 'response' => 'add files.'} end
function download_patient_folder(patient_id){ var $url = 'docsnaphomes/download_folder'; $.post($url, {patient_id: patient_id}, function(data){ window.location = data.response; }); }
Comments
Post a Comment