2011-09-07 89 views
0

我開發了一個Grails應用程序,它具有用戶文件上傳(文檔等),它們存儲在相關文件夾「web-app/upload」中。戰爭中的grails文件上傳管理

我的問題是,我不知道什麼是自動執行戰爭部署並保留此文件夾的最佳方式。因爲當我在Tomcat中重新部署時,整個應用程序文件夾將被刪除,並且所有文件都將被刪除。

Additionaly我需要一個通用的配置弗朗從這個文件

設置外部位置,你已經找到了一個解決方案?

P.D .:如果我使用System.properties ['base.dir'],結果爲null,如果我使用ApplicationHolder.application.mainContext.getResource(),它將返回一個臨時路徑。 :(

回答

2

你不應該上傳文件到您的WAR結構,你應該把它們上傳到一些外部的位置。

+0

好吧,我早就知道了,怎麼一回事,因爲我寫的: 「Additionaly我需要一個通用的配置弗朗從這個文件中設置外部位置」 我需要的是一個通用配置,給我的路徑,我的應用程序的目錄容器。 – yecid

1

我能夠解決部分如下

//for development environment 
    def root = System.properties['base.dir']?.toString() 
    if(!root){ 
     //for production environment in war deplements 
     def tmpRoot = ApplicationHolder.application.mainContext.getResource('WEB-INF').getFile().toString() 
     root = tmpRoot.substring(0, tmpRoot.indexOf(File.separator + 'temp' + File.separator)) 
    } 
    if(!root){ 
     throw new Exception('Not found a valid path') 
    } 
    return root + File.separator 

我希望它可以有用的其他

問候, Yecid太平洋

1

此代碼獲取父文件夾,其中應用程序是LOCAT編輯:

String path = servletContext.getRealPath("/"); 
String parentStr = new File(path).getParentFile().getParent(); 

我的意思是,如果Web應用程序均位於d:\ somefolder \ MYWEB

pathd:\ somefolder \ MYWEB \ web-app的

parentStr將是D:\ somefolder

因此,您可以將文件保存在D:\ somefolder \ files-outside-myWeb-context

這是你在找什麼?