I have a system where I can upload files through an Angular library ( ng-file-upload
), but if the file is larger than 3MB when I try to upload, I have the following errors:
GRAVE: Servlet.service () for servlet [default] in context with path [/ Union] threw exception br.com.caelum.vraptor.InterceptionException: br.com.caelum.vraptor.InterceptionException: java.lang.IllegalStateException: There are validation errors and you forgot to specify where to go. Please add in your method something like validator.onErrorUse (page ()) of (AnyController.class) .anyMethod (); or any view that you like If you did not add any validation error, it is possible that a conversion had happened. at br.com.caelum.vraptor.interceptor.StepInvoker.invokeMethod (StepInvoker.java:54)
Caused by: java.lang.IllegalStateException: There are validation errors and you forgot to specify where to go. Please add in your method something like: validator.onErrorUse (page ()) of (AnyController.class) .anyMethod (); or any view that you like If you did not add any validation error, it is possible that a conversion had happened. at br.com.caelum.vraptor.validator.Messages.assertAbsenceOfErrors (Messages.java:108) at $ weldClientProxy.assertAbsenceOfErrors (Unknown) Source) at br.com.caelum.vraptor.core.DefaultResult.use (DefaultResult.java:79) at br.caelum.vraptor.core.DefaultResult $ Proxy $ $$ _ WeldClientProxy.use (Unknown Source) at com.union.controller.CORSInterceptor.intercept (CORSInterceptor.java:25)
In that second exception there is an error in my CORS interceptor:
@Intercepts
public class CORSInterceptor {
@Inject
private Result result;
@Inject
private HttpServletRequest request;
@BeforeCall
public void intercept() throws InterceptionException {
// Fix your origin if possible for security reasons
String origin = request.getHeader("origin") != null ? request.getHeader("origin") : "*";
result.use(Results.status()).header("Access-Control-Allow-Origin", origin); //Linha 25
result.use(Results.status()).header("Access-Control-Allow-Credentials", "true");
result.use(Results.status()).header("Access-Control-Expose-Headers", "Content-Type, Location");
}
}
This is my method that receives the front image and saves it to a directory:
@Post
@Path(value = "/imagem")
public void salvaImagem(UploadedFile file) throws IOException {
System.out.println("SALVAR IMAGEM");
try{
InputStream in = new BufferedInputStream(file.getFile());
File fotoSalva = new File(DIRETORIO_UPLOAD, file.getFileName());
System.out.println(fotoSalva);
FileOutputStream fos = new FileOutputStream(fotoSalva);
while (in.available() != 0) {
fos.write(in.read());
}
fos.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
I'm validating the upload in front
for it to accept files up to 10MB, and that's alright, the problem is that back-end
can not get these files.