我有一个简单的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