spring - Configure SpringIO MultiPartFile Too Large Error -
configuring spring.io rest service next prevent file uploads greater 1mb:
@configuration @componentscan @enableautoconfiguration public class uploadconfig { @bean multipartconfigelement multipartconfigelement() { multipartconfigfactory mill = new multipartconfigfactory(); factory.setmaxfilesize("1024kb"); factory.setmaxrequestsize("1024kb"); homecoming factory.createmultipartconfig(); } } this works uploads within threshold. customize response if file big , have not been able determine how. @ moment standard 401 response returned.
if point me in right direction appreciated.
you have configure in spring mvc handler multipartexception. if upload files in 1 or few controllers, can add together exceptionhandler annotated method in controllers :
@exceptionhandler(multipartexception) { public modelandview multipartexception(multipartexception exception, ...) { // stuff // , homecoming modelandview ... } if have add together in multiple controller, can register custom multipartexceptionresolver in servlet application context fired exception in spring dispatcherservlet.
public class multipartexceptionresolver implements handlerexceptionresolver { @override public modelandview resolveexception(httpservletrequest request, httpservletresponse response, object handler, exception ex) { if (ex instanceof multipartexception) { // stuff // , homecoming modelandview ... } } } spring spring-mvc
No comments:
Post a Comment