# Controller responsible for serving files and pictures. class FileController < ApplicationController layout 'default' before_filter :check_allow_uploads def file if @params['file'] # form supplied new_file = upload_file(@file_name, @params['file']) if new_file.valid? flash[:info] = "File '#{@file_name}' successfully uploaded" return_to_last_remembered else # FIXME handle validation errors more gracefully flash[:errors] = new_file.errors.to_s end else # no form supplied, this is a request to download the file file = WikiFile.find_by_file_name(@file_name) if file send_data(file.content, :filename => @file_name, :type => content_type_header(@file_name)) end end # if it's neither a supplied form for upload, nor a request for a known file, # display the file/file.rhtml template (which happens to be an upload form) end def cancel_upload return_to_last_remembered end def import if @params['file'] @problems = [] import_file_name = "#{@web.address}-import-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.zip" file_yard.upload_file(import_file_name, @params['file']) import_from_archive(file_yard.file_path(import_file_name)) if @problems.empty? flash[:info] = 'Import successfully finished' else flash[:error] = "Import finished, but some pages were not imported: