The UploadController provides access to the different upload plugins that have been deployed in the dradis server.

Each upload plugin will include itself in the Plugins::Upload module and this controller will include it so all the functionality provided by the different plugins is exposed.

A convenience list method is provided that will return all the currently loaded plugins of this category.

Methods
Included Modules
Public Instance methods
import()

This method handles the execution flow to the requested :uploader. It first copies the uploaded file into the configured uploads node (see Configuration.uploadsNode). Then the request is passed to the chosen plugin.

    # File app/controllers/upload_controller.rb, line 51
51:   def import 
52:     # create an 'Imported files' node
53:     uploadsNode = Node.find_or_create_by_label(Configuration.uploadsNode)
54:    
55:     # add the file as an attachment
56:     attachment = Attachment.new( params[:file].original_filename, :node_id => uploadsNode.id )
57:     attachment << params[:file].read
58:     attachment.save
59: 
60:     #Increment revision
61:     Configuration.increment_revision 
62:  
63:     # process the upload using the plugin
64:     begin
65:       @uploader.import(:file => attachment)
66:     
67:       # Notify the caller that everything was fine
68:       render :text => { :success=>true }.to_json
69: 
70:     rescue Exception => e
71:       # Something went wrong
72:       render :text => { :error => e.message, :backtrace => e.backtrace }.to_json
73:     end
74:   end
list()

This method provides a list of all the available uploader plugins. It assumes that each export plugin inclides instance methods in the Plugins::Upload mixing.

    # File app/controllers/upload_controller.rb, line 31
31:   def list
32:     respond_to do |format|
33:       format.html{ redirect_to '/' }
34:       format.json{ 
35:         list = []
36:         Plugins::Upload.included_modules.each do |plugin|
37:           list << { 
38:             :name => plugin.name.underscore.humanize.gsub(/\//,' - '), 
39:             :plugin => plugin.name 
40:           }
41:         end
42: 
43:         render :json => list
44:       }
45:     end
46:   end