Upload de Arquivo está NULL

129 views
Skip to first unread message

Thiago Augusto

unread,
Nov 28, 2013, 8:48:36 AM11/28/13
to caelum-vr...@googlegroups.com
Olá, pessoal sou novo no forum e já estou com duvidas.

Estou fazendo um upload de uma imagem, mas meu arquivo vem NULL. Já alterei a versão do Vraptor para 3.1.2 / 3.3.1 / 3.5.3, mas nada.

O que eu estou fazendo de errado? Estou usando o Tomcat 7.

Segue mau código.

Meu método Upload:
 public void upload(UploadedFile arq) throws IOException { 
        try{
            File destino = new File(arq.getFileName());
            IOUtils.copy(arq.getFile(), new FileOutputStream(destino));
        }catch (FileNotFoundException e) {
             e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
     }

Minha Exception:
java.lang.NullPointerException
	com.download.teste.Imagens.upload(Imagens.java:45)
	com.download.controller.ImagemController.upload(ImagemController.java:36)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	java.lang.reflect.Method.invoke(Unknown Source)
	br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:57)
	br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor.intercept(ParametersInstantiatorInterceptor.java:77)
	br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:42)
	br.com.caelum.vraptor.core.InstantiatedInterceptorHandler.execute(InstantiatedInterceptorHandler.java:47)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.interceptor.InterceptorListPriorToExecutionExtractor.intercept(InterceptorListPriorToExecutionExtractor.java:46)
	br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:81)
	br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:67)
	br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.interceptor.multipart.MultipartInterceptor.intercept(MultipartInterceptor.java:111)
	br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
	br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
	br.com.caelum.vraptor.core.DefaultRequestExecution.execute(DefaultRequestExecution.java:70)
	br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:92)
	br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:56)
	br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:89)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.

Carlos Alberto Junior Spohr Poletto

unread,
Nov 28, 2013, 8:52:06 AM11/28/13
to caelum-vr...@googlegroups.com
Bom, se você está com a biblioteca, então pode ser que você não tenha colocado a tag enctype="multipart/form-data" no seu form.


--
You received this message because you are subscribed to the Google Groups "caelum-vraptor-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caelum-vraptor-...@googlegroups.com.
To post to this group, send email to caelum-vr...@googlegroups.com.
Visit this group at http://groups.google.com/group/caelum-vraptor-dev.

For more options, visit https://groups.google.com/groups/opt_out.



--
Atenciosamente,
Carlos Alberto Junior Spohr Poletto

Thiago Augusto

unread,
Nov 28, 2013, 8:56:25 AM11/28/13
to caelum-vr...@googlegroups.com
Meu JSP está assim...

<form action="<c:url value="/download/downloadArquivo"/>" enctype="multipart/form-data" method="POST">
            <fieldset>
                     <legend>Download</legend> 
                <button type="submit">Download</button>
                <br/>
            </fieldset>
           
        </form>

Thiago Augusto

unread,
Nov 28, 2013, 8:58:19 AM11/28/13
to caelum-vr...@googlegroups.com
Ops, desculpa postei o JSP errado. Meu JSP é este.

<form action="<c:url value="/upload/uploadArquivo"/>" enctype="multipart/form-data" method="POST">
            <fieldset>
                     <legend>Upload</legend> 
                Imagem: <input type="file" name="imagem"/>
                <br/><br/>
                <button type="submit">Fazer Upload</button> 
            </fieldset>
        </form>

Em quinta-feira, 28 de novembro de 2013 11h48min36s UTC-2, Thiago Augusto escreveu:

Carlos Alberto Junior Spohr Poletto

unread,
Nov 28, 2013, 10:17:06 AM11/28/13
to caelum-vr...@googlegroups.com
Olha na sua classe Controller:

 public void upload(UploadedFile arq) throws IOException {  
...
}


O nome do argumento deve ser o mesmo do seu form HTML:

HTML:
<input type="file" name="imagem"/>

Java:
public void upload(UploadedFile imagem) throws IOException {  ..}




--
You received this message because you are subscribed to the Google Groups "caelum-vraptor-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caelum-vraptor-...@googlegroups.com.
To post to this group, send email to caelum-vr...@googlegroups.com.
Visit this group at http://groups.google.com/group/caelum-vraptor-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Otávio Garcia

unread,
Nov 28, 2013, 10:39:24 AM11/28/13
to caelum-vr...@googlegroups.com
Thiago, bem vindo ao VRaptor. :)

Evite postar a mesma dúvida nas suas listas. E use sempre a lista
caelum-vraptor, que é destinada a usuários.

A lista caelum-vraptor-dev é destinada a assuntos de desenvolvimento do vraptor.

Abraço

Sent from my Motorola Atrix™

Renan Oliveira

unread,
Nov 28, 2013, 10:45:40 AM11/28/13
to caelum-vr...@googlegroups.com
Deve faltar dependencia commons-fileupload no projeto.


2013/11/28 Carlos Alberto Junior Spohr Poletto <carlos...@gmail.com>

Thiago Augusto

unread,
Nov 28, 2013, 11:11:29 AM11/28/13
to caelum-vr...@googlegroups.com
Carlos Alberto, Era isso mesmo. Comecei a utilizar o framework a pouco tempo, por isso esse erro bizarro..

Obrigado.

Em quinta-feira, 28 de novembro de 2013 11h48min36s UTC-2, Thiago Augusto escreveu:

Carlos Alberto Junior Spohr Poletto

unread,
Nov 28, 2013, 11:18:46 AM11/28/13
to caelum-vr...@googlegroups.com
Na paz mano, bom proveito com o VRaptor.


--
You received this message because you are subscribed to the Google Groups "caelum-vraptor-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caelum-vraptor-...@googlegroups.com.
To post to this group, send email to caelum-vr...@googlegroups.com.
Visit this group at http://groups.google.com/group/caelum-vraptor-dev.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages