Added file uploader

Uploaded map files will be saved in /redmine/public/data

refs #16
This commit is contained in:
2012-04-26 10:56:28 -04:00
parent 6bbf73a85a
commit 228ff2b8d4
4 changed files with 24 additions and 8 deletions

View File

@@ -28,4 +28,9 @@ class MapsController < ApplicationController
end end
def uploadFile
post = Map.save(params[:upload])
render :text => "File has been uploaded successfully"
end
end #EOF end #EOF

View File

@@ -22,4 +22,16 @@
# if not a new bug issue will be generated. # if not a new bug issue will be generated.
class Map < ActiveRecord::Base class Map < ActiveRecord::Base
unloadable 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 end

View File

@@ -1,8 +1,7 @@
<h1>Exception Handler Maps</h1> <h1>Exception Handler Maps</h1>
<br/> <br/>
<!-- TODO uploader action --> <%= form_tag ({:action => 'uploadFile'}, :multipart => true) %>
<form action="XXX" method="post" enctype="multipart/form-data">
<label for="package">Package:</label> <label for="package">Package:</label>
<br/> <br/>
<input name="package" id="package" type="text" maxlength="5555500" size=50%/> <input name="package" id="package" type="text" maxlength="5555500" size=50%/>
@@ -11,10 +10,9 @@
<br/> <br/>
<input name="build" id="build" type="text" maxlength="5555500" size=50%/> <input name="build" id="build" type="text" maxlength="5555500" size=50%/>
<br/> <br/>
<label for="file">File:</label> <%= form_tag ({:action => 'uploadFile'}, :multipart => true) %>
<p><label for="upload_file">Select File</label> :
<br/> <br/>
<input type="file" name="file" id="file" accept="text/plain" /> <%= file_field 'upload', 'datafile' %></p>
<br/> <%= submit_tag "Upload" %>
<br/> <%= form_tag %>
<input type="submit" name="submit" value="Submit" />
</form>

View File

@@ -23,4 +23,5 @@
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.connect '/exceptionhandler', :controller => 'exceptionhandler', :action => 'index' map.connect '/exceptionhandler', :controller => 'exceptionhandler', :action => 'index'
map.connect '/maps', :controller => 'maps', :action => 'index' map.connect '/maps', :controller => 'maps', :action => 'index'
map.connect '/uploadFile', :controller => 'maps', :action => 'uploadFile'
end end