diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index a4027ca..6abece2 100755 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -28,4 +28,9 @@ class MapsController < ApplicationController end + def uploadFile + post = Map.save(params[:upload]) + render :text => "File has been uploaded successfully" + end + end #EOF diff --git a/app/models/map.rb b/app/models/map.rb index fa74131..5efbfd0 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -22,4 +22,16 @@ # if not a new bug issue will be generated. class Map < ActiveRecord::Base unloadable + + require 'digest/sha1' + + def self.save(upload) + name = upload['datafile'].original_filename + directory = "public/data" + sha1 = Digest::SHA1.hexdigest name + # create the file path + path = File.join(directory, sha1) + # write the file + File.open(path, "wb") { |f| f.write(upload['datafile'].read) } + end end diff --git a/app/views/maps/index.html.erb b/app/views/maps/index.html.erb index 6a80a5f..891f533 100755 --- a/app/views/maps/index.html.erb +++ b/app/views/maps/index.html.erb @@ -1,8 +1,7 @@

Exception Handler Maps


- -
+<%= form_tag ({:action => 'uploadFile'}, :multipart => true) %>
@@ -11,10 +10,9 @@

- + <%= form_tag ({:action => 'uploadFile'}, :multipart => true) %> +

:
- -
-
- -

+ <%= file_field 'upload', 'datafile' %>

+ <%= submit_tag "Upload" %> +<%= form_tag %> diff --git a/config/routes.rb b/config/routes.rb index 8b264a9..4a6fe68 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,4 +23,5 @@ ActionController::Routing::Routes.draw do |map| map.connect '/exceptionhandler', :controller => 'exceptionhandler', :action => 'index' map.connect '/maps', :controller => 'maps', :action => 'index' + map.connect '/uploadFile', :controller => 'maps', :action => 'uploadFile' end