本文介绍了上传文件抛出方法异常没有签名(在getFile()方法中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图上传一个文件,并将其存储在一个文件中。这是GSP中的代码: < g:form method =postenctype =multipart / form-data action =update>
< input type =filename =cvid =cv/>
< / g:表格>
在控制器中:
def upload(){
def f = request.getFile('cv')
InputStream file = f.inputStream
byte [] bytes = file.bytes
println('bytes:'+ bytes)
}
标题,我在这里得到一个例外。任何帮助?谢谢。
编辑(Full Stacktrace,按要求):
错误500:内部服务器错误
URI
/com.publidirecta.azafatas/azafataCertificada/index
类
groovy.lang.MissingMethodException
消息
没有方法的签名:org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper.getFile()适用于参数类型:(java.lang.String)values:[cv]可能的解决方案:getXML(),getPart(java ().getString),getAt(java.lang.String),getAt(java.lang.String),getLocale(),getJSON()
在grails-app / controllers / com的第1158行/publidirecta/AzafataCertificadaController.groovy
$ b 1155:def upload(){
1156:println(Acci√≥nupload。Params:+ params)
1157:Azafata aza = Azafata.findByUsername(params.user)
1158:def f = request.getFile('cv')
1159:InputStream file = f.inputStream
1160:byte [] bytes = file .bytes
1161:}
跟踪
Line |方法
- >> 1158 |上传到AzafataCertificadaController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 886 | java.util.concurrent.ThreadPoolExecutor中的runTask $ Worker
| 908 |跑 。 。 in''
^ 680 |在java.lang.Thread中运行
解决方案
问题是您的请求不被视为MultiPartRequest。做这样的事情:
MultipartRequest multipartRequest = request作为MultipartRequest
if(multipartRequest){
MultipartFile attachmentFile = multipartRequest.getFile(attachment_file.toString())
if(attachmentFile){
- copy it ---
}
}
Im trying to upload a file, and store it in a file. This is the code in the GSP:
<g:form method="post" enctype="multipart/form-data" action="update">
<input type="file" name="cv" id="cv"/>
<g:actionSubmit action="upload" name="upload" value="Upload" />
</g:form>
In the Controller:
def upload(){
def f = request.getFile('cv')
InputStream file = f.inputStream
byte[] bytes = file.bytes
println('bytes: '+bytes)
}
As I say in the title, i got an exception here. Any help? Thanks.
EDIT (Full Stacktrace, by request):
Error 500: Internal Server Error
URI
/com.publidirecta.azafatas/azafataCertificada/index
Class
groovy.lang.MissingMethodException
Message
No signature of method:org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [cv] Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON()
Around line 1158 of grails-app/controllers/com/publidirecta/AzafataCertificadaController.groovy
1155: def upload(){
1156: println("Acción upload. Params: "+params)
1157: Azafata aza=Azafata.findByUsername(params.user)
1158: def f = request.getFile('cv')
1159: InputStream file = f.inputStream
1160: byte[] bytes = file.bytes
1161: }
Trace
Line | Method
->> 1158 | upload in AzafataCertificadaController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . in ''
^ 680 | run in java.lang.Thread
解决方案
The problem is that your request is not treated as a MultiPartRequest. Do something like this:
MultipartRequest multipartRequest = request as MultipartRequest
if(multipartRequest){
MultipartFile attachmentFile = multipartRequest.getFile("attachment_file".toString())
if (attachmentFile) {
-- copy it ---
}
}
这篇关于上传文件抛出方法异常没有签名(在getFile()方法中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!