Grails 2.4.4文件存在时文件上载错误

Grails 2.4.4文件存在时文件上载错误,grails,file-upload,Grails,File Upload,我有一个操作,可以正确接收文件并将其保存到目标文件夹,而不会出现问题 当目标文件夹中有同名文件时,transferTo方法首先删除现有文件,然后复制新文件() 但是如果目标文件存在,Grails将抛出此错误,并且删除现有文件,但不会复制上载的文件 我在WinXP中工作,所以我不认为这是权限问题(文件被删除了,所以我猜与权限无关) |错误2015-05-24 23:47:58199[http-bio-8090-exec-3]错误。GrailExceptionResolver-处理请求时发生File

我有一个操作,可以正确接收文件并将其保存到目标文件夹,而不会出现问题

当目标文件夹中有同名文件时,transferTo方法首先删除现有文件,然后复制新文件()

但是如果目标文件存在,Grails将抛出此错误,并且删除现有文件,但不会复制上载的文件

我在WinXP中工作,所以我不认为这是权限问题(文件被删除了,所以我猜与权限无关)

|错误2015-05-24 23:47:58199[http-bio-8090-exec-3]错误。GrailExceptionResolver-处理请求时发生FileNotFoundException:[POST]/ehr/test/upload-参数:
doit:上传
覆盖:真
同步器令牌:8deaf46b-b6ff-4362-ac70-7223f37ae806
同步器URI:/ehr/测试/上传
opts\Signos.opt(访问被拒绝)。跟踪如下:
消息:opts\Signos.opt(访问被拒绝)
直线法
->>221 |在java.io.FileOutputStream中
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|171英寸“
|417 |写。在org.apache.commons.fileupload.disk.DiskFileItem中
|85 |在test.TestController中上载
|198 | grails.plugin.cache.web.filter.PageFragmentCachingFilter中的doFilter
|63 | grails.plugin.cache.web.filter.AbstractFilter中的doFilter
|1145 | java.util.concurrent.ThreadPoolExecutor中的runWorker
|615 |在java.util.concurrent.ThreadPoolExecutor$Worker中运行
^744 |跑。在java.lang.Thread中
上载操作如下所示:

def upload(boolean overwrite)
{
  if (params.doit)
  {
     def errors = []

     def f = request.getFile('opt')
     def xml = new String( f.getBytes() )
     def destination = config.opt_repo + f.getOriginalFilename() 
     File fileDest = new File( destination )

     if (!overwrite && fileDest.exists())
     {
        errors << "The OPT already exists, do you want to overwrite?"
        return [errors: errors, ask_overwrite: true]
     }

     // Some validation logic here ...

     if (errors.size() == 0)
     {
        // http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/commons/CommonsMultipartFile.html#transferTo-java.io.File-
        // If the file exists, it will be deleted first
        f.transferTo(fileDest)
     }
  }
}
def上传(布尔覆盖)
{
if(参数doit)
{
def错误=[]
def=request.getFile('opt')
def xml=新字符串(f.getBytes())
def destination=config.opt_repo+f.getOriginalFilename()
File fileDest=新文件(目标)
如果(!overwrite&&fileDest.exists())
{
错误
def upload(boolean overwrite)
{
  if (params.doit)
  {
     def errors = []

     def f = request.getFile('opt')
     def xml = new String( f.getBytes() )
     def destination = config.opt_repo + f.getOriginalFilename() 
     File fileDest = new File( destination )

     if (!overwrite && fileDest.exists())
     {
        errors << "The OPT already exists, do you want to overwrite?"
        return [errors: errors, ask_overwrite: true]
     }

     // Some validation logic here ...

     if (errors.size() == 0)
     {
        // http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/multipart/commons/CommonsMultipartFile.html#transferTo-java.io.File-
        // If the file exists, it will be deleted first
        f.transferTo(fileDest)
     }
  }
}