gpt4 book ai didi

grails - 上载文件引发方法异常没有签名(在getFile()方法中)

转载 作者:行者123 更新时间:2023-12-02 14:02:56 30 4
gpt4 key购买 nike

我正在尝试上传文件,并将其存储在文件中。这是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>

在 Controller 中:
def upload(){
def f = request.getFile('cv')
InputStream file = f.inputStream
byte[] bytes = file.bytes
println('bytes: '+bytes)
}

就像我在标题中所说的,我在这里有一个异常(exception)。有什么帮助吗?谢谢。

编辑(完整的Stacktrace,通过请求):
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

最佳答案

问题在于您的请求没有被视为MultiPartRequest。做这样的事情:

MultipartRequest multipartRequest =  request as MultipartRequest
if(multipartRequest){
MultipartFile attachmentFile = multipartRequest.getFile("attachment_file".toString())
if (attachmentFile) {
-- copy it ---
}
}

关于grails - 上载文件引发方法异常没有签名(在getFile()方法中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14259264/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com