5
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 didn’t add any validation error, it is possible that a Conversion error 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 didn’t add any validation error, it is possible that a Conversion error had happened. at br.com.Caelum.vraptor.Validator.Messages.assertAbsenceOfErrors(Messages.java:108) at br.com.Caelum.vraptor.Validator.Messages$Proxy$_$$Weldclientproxy.assertAbsenceOfErrors(Unknown Source) at br.com.Caelum.vraptor.core.DefaultResult.use(Defaultresult.java:79) at br.com.Caelum.vraptor.core.Defaultresult$Proxy$$$_Weldclientproxy.use(Unknown Source) at com.union.controller.CORSInterceptor.Intercept(Corsinterceptor.java:25)
In this second Exception gives an error in my Interceptor that treats CORS:
@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 in 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 on front
for it to accept files up to 10MB, and it’s all right, the same problem is that the back-end
can’t get those files.