Added file uploader
Uploaded map files will be saved in /redmine/public/data refs #16
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<h1>Exception Handler Maps</h1>
|
||||
<br/>
|
||||
|
||||
<!-- TODO uploader action -->
|
||||
<form action="XXX" method="post" enctype="multipart/form-data">
|
||||
<%= form_tag ({:action => 'uploadFile'}, :multipart => true) %>
|
||||
<label for="package">Package:</label>
|
||||
<br/>
|
||||
<input name="package" id="package" type="text" maxlength="5555500" size=50%/>
|
||||
@@ -11,10 +10,9 @@
|
||||
<br/>
|
||||
<input name="build" id="build" type="text" maxlength="5555500" size=50%/>
|
||||
<br/>
|
||||
<label for="file">File:</label>
|
||||
<%= form_tag ({:action => 'uploadFile'}, :multipart => true) %>
|
||||
<p><label for="upload_file">Select File</label> :
|
||||
<br/>
|
||||
<input type="file" name="file" id="file" accept="text/plain" />
|
||||
<br/>
|
||||
<br/>
|
||||
<input type="submit" name="submit" value="Submit" />
|
||||
</form>
|
||||
<%= file_field 'upload', 'datafile' %></p>
|
||||
<%= submit_tag "Upload" %>
|
||||
<%= form_tag %>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user