Finished uploader
sha1 is now based on content's of file public/maps is now created if it doesn't exist closes #16
This commit is contained in:
@@ -40,21 +40,27 @@ class Map < ActiveRecord::Base
|
|||||||
|
|
||||||
upload = p[:upload]
|
upload = p[:upload]
|
||||||
name = upload['datafile'].original_filename
|
name = upload['datafile'].original_filename
|
||||||
directory = "public/data"
|
directory = "public/maps"
|
||||||
sha1 = Digest::SHA1.hexdigest name
|
|
||||||
|
|
||||||
map.map = sha1
|
if !File.directory? directory
|
||||||
|
Dir.mkdir(directory, 0700)
|
||||||
if map.save
|
|
||||||
|
|
||||||
# create the file path
|
|
||||||
path = File.join(directory, sha1)
|
|
||||||
# write the file
|
|
||||||
File.open(path, "wb") { |f| f.write(upload['datafile'].read) }
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sha1 = Digest::SHA1.new
|
||||||
|
|
||||||
|
# create the file path
|
||||||
|
path = File.join(directory, name)
|
||||||
|
# write the file
|
||||||
|
File.open(path, "wb") { |f|
|
||||||
|
data = upload['datafile'].read
|
||||||
|
f.write(data)
|
||||||
|
sha1.update(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
File.rename(directory+'/'+name, directory +'/'+ sha1.hexdigest)
|
||||||
|
|
||||||
|
map.map = sha1.hexdigest
|
||||||
|
map.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def getMap()
|
def getMap()
|
||||||
|
|||||||
Reference in New Issue
Block a user