Tôi có ứng dụng tải lên tệp grails đơn giản.grails base.dir thuộc tính hệ thống
Tôi đang sử dụng transferTo để lưu tệp vào hệ thống tệp.
Để có được con đường cơ bản trong điều khiển của tôi Tôi đang sử dụng
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"
Đối với một số lý do này luôn là null khi triển khai để tôi WS 6.1 máy chủ.
Tại sao nó hoạt động khi chạy dev nhưng không hoạt động trên máy chủ WS? Tôi có nên truy cập thông tin này theo cách khác không?
Đây là một cách tốt hơn để đi hơn câu trả lời được chấp nhận hiện nay. –