简体   繁体   English

Grails 3.2 文件上传错误 (FileNotFoundException )

[英]Grails 3.2 File Upload Error (FileNotFoundException )

I'm trying to run a Grails 3.2 web application with Tomcat 8 on Windows 10 that involves file upload.我正在尝试在涉及文件上传的 Windows 10 上使用 Tomcat 8 运行 Grails 3.2 Web 应用程序。 The webApp launches correctly but when I try to upload any file remotely I keep getting the file error below. webApp 正确启动,但是当我尝试远程上传任何文件时,我不断收到以下文件错误。 Notice in the message there are two absolute paths jammed together, which would make for an invalid file specification.请注意,消息中有两个绝对路径卡在一起,这将导致文件规范无效。 I do not get this error when I access the application inside the host machine using localhost as the IP address.当我使用 localhost 作为 IP 地址访问主机内的应用程序时,我没有收到此错误。 Any help is appreciated.任何帮助表示赞赏。

<g:uploadForm name="sstForm" controller="sstSetup" method="POST" >
    <input id="w-mdf" type="file" name="wMDF" />&nbsp;&nbsp;

    <div class="yui3-u-25-100" id="setup-submit">
        <g:actionSubmit class="input block-page" name="submit" value="Submit" action="setupAction" onclick="return validateInput();"/>
        <g:actionSubmit class="inputGrey block-page" name="cancel" value="Cancel" action="cancel"/>
    </div>
</g:uploadForm>

Then on the server side I grab the MultiPart file object in the controller and call tranferTo to convert it to a normal file然后在服务器端我抓取控制器中的 MultiPart 文件对象并调用 tranferTo 将其转换为普通文件

File fileDest = new File("Path to some destination and file name")

multipartFile.transferTo(fileDest)

Nothing complicated here.这里没有什么复杂的。 Yet it is throwing FileNotFoundException when the upload is coming from a remote location.然而,当上传来自远程位置时,它会抛出 FileNotFoundException 。

Error: java.io.FileNotFoundException: D:\\Users\\RWSK70\\Documents\\Clark\\CIM\\Misc\\Drools\\DroolsIntelliJProject\\drools-app\\target\\classes\\rules\\C:\\Users\\RWSK70\\Documents\\Clark\\!!\\CIM\\Misc\\Drools\\DroolsIntelliJProject\\drools-app\\src\\rules\\application\\1233275_RSF_v243.txt (The filename, directory name, or volume label syntax is incorrect)错误:java.io.FileNotFoundException:D:\\Users\\RWSK70\\Documents\\Clark\\CIM\\Misc\\Drools\\DroolsIntelliJProject\\drools-app\\target\\classes\\rules\\C:\\Users\\RWSK70\\Documents\\Clark\\!! \\CIM\\Misc\\Drools\\DroolsIntelliJProject\\drools-app\\src\\rules\\application\\1233275_RSF_v243.txt(文件名、目录名或卷标语法不正确)

I found the Issue.我找到了问题。 It was caused by the way I handled the uploaded Multipart file.这是由我处理上传的 Multipart 文件的方式引起的。 The Servlet specification gave clients the leeway to return either the filename or the absolute path of the file when multipart.getOriginalFilename() is called. Servlet 规范为客户端提供了在调用 multipart.getOriginalFilename() 时返回文件名或文件绝对路径的余地。 I made the erroneous assumption that clients will always return the simple filename based on experience.我错误地假设客户总是根据经验返回简单的文件名。 This is a wrong assumption.这是一个错误的假设。 It turned out that in this one production environment, their browsers were sending the absolute path of the file instead of the simple filename which the application was expecting and that did not go well.事实证明,在这个生产环境中,他们的浏览器发送的是文件的绝对路径,而不是应用程序期望的简单文件名,这并不顺利。 – Felix Andrews Dec 2 at 18:53 – 菲利克斯·安德鲁斯 12 月 2 日 18:53

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM