我有一個簡單的grails文件上傳應用程序。grails base.dir系統屬性
我正在使用transferTo將文件保存到文件系統。
爲了讓我使用
def basePath = System.properties['base.dir'] // HERE IS HOW I GET IT
println "Getting new file"
println "copying file to "+basePath+"/files"
def f = request.getFile('file')
def okcontents = ['application/zip','application/x-zip-compressed']
if (! okcontents.contains(f.getContentType())) {
flash.message = "File must be of a valid zip archive"
render(view:'create', model:[zone:create])
return;
}
if(!f.empty) {
f.transferTo(new File(basePath+"/files/"+zoneInstance.title+".zip"))
}
else
{
flash.message = 'file cannot be empty'
redirect(action:'upload')
}
println "Done getting new file"
出於某種原因,在部署到我WAS 6.1的服務器,這是始終爲空在我的控制器的基本路徑。
爲什麼在運行dev時工作但不在WAS服務器上運行?我應該以不同的方式訪問這些信息嗎?
這是一個更好的方式去比目前公認的答案。 – 2014-11-03 18:21:17