gpt4 book ai didi

grails - Grails 2.4限制/最大上传大小

转载 作者:行者123 更新时间:2023-12-02 15:06:09 25 4
gpt4 key购买 nike

关于https://brainflush.wordpress.com/2008/12/04/how-to-gracefully-recover-from-file-upload-errors-in-grails/,我无法在Grails 2.4上使用它。

我已将此添加到我的Grails应用程序中:

resources.groovy

beans = {
multipartResolver(CustomMultipartResolver) {
maxUploadSize = 2000000
}
}

添加到BootStrap.groovy
public class CustomMultipartResolver extends CommonsMultipartResolver {

static final String FILE_SIZE_EXCEEDED_ERROR = "fileSizeExceeded"

public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) {

try {
return super.resolveMultipart(request)
} catch (MaxUploadSizeExceededException e) {
request.setAttribute(FILE_SIZE_EXCEEDED_ERROR, true)
return new DefaultMultipartHttpServletRequest(request, new LinkedMultiValueMap(), [:])
} catch (SizeLimitExceededException e) {
request.setAttribute(FILE_SIZE_EXCEEDED_ERROR, true)
return new DefaultMultipartHttpServletRequest(request, new LinkedMultiValueMap(), [:])
}
}
}

在 Controller 中:
if (request.getAttribute(CustomMultipartResolver.FILE_SIZE_EXCEEDED_ERROR)) {
ModActionFile.errors.reject("MyDomain.fileSizeTooLarge")
redirect(controller:'MyDomain', action:'create',params:params)
} else {...

我得到这个错误
Error |
2015-03-17 16:08:57,794 [http-bio-8080-exec-8] ERROR [/tool].[default] - Servlet.service() for servlet [default] in context with path [/tool] threw exception
Message: Could not find matching constructor for: org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest(org.apache.catalina.connector.RequestFacade, org.springframework.util.LinkedMultiValueMap, java.util.LinkedHashMap)
Line | Method
->> 43 | resolveMultipart in CustomMultipartResolver$$EP7CaraR
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread

最佳答案

2008年很久以前。

错误消息非常清楚-您正在将错误的类型传递给构造函数,或者传递了错误的参数数量。

Grails 2.4.4使用Spring 4.0.7,并且该类具有两个构造函数:

public DefaultMultipartHttpServletRequest(HttpServletRequest request, MultiValueMap<String, MultipartFile> mpFiles,
Map<String, String[]> mpParams, Map<String, String> mpParamContentTypes)


public DefaultMultipartHttpServletRequest(HttpServletRequest request)

您可以看到 here

这应该工作:
class CustomMultipartResolver extends CommonsMultipartResolver {

static final String FILE_SIZE_EXCEEDED_ERROR = 'fileSizeExceeded'

MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) {
try {
super.resolveMultipart request
}
catch (MaxUploadSizeExceededException e) {
request.FILE_SIZE_EXCEEDED_ERROR = true
new DefaultMultipartHttpServletRequest(request, new LinkedMultiValueMap(), [:], [:])
}
catch (SizeLimitExceededException e) {
request.FILE_SIZE_EXCEEDED_ERROR = true
new DefaultMultipartHttpServletRequest(request, new LinkedMultiValueMap(), [:], [:])
}
}
}

关于grails - Grails 2.4限制/最大上传大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29104004/

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