Olá pessoal Blz…
Estou usando o FileUpload e etá acontecendo algo estranho no IE6 ele não faz o upload dos aquivos já no Opera e FireFox … roda que é uma beleza.
"Não é de se admirar
"
no Form estou usando assim.
<form action="ServletUpload" method="post" enctype="multipart/form-data" >
porque será que no IE6 tá dando erro ? :roll:
Obrigado
Ele dá um nullPointerExecption, se eu estiver usando o IE, quando eu tento escrevr o arquivo no disco, no Firefox é uma belza
Provavelmente vc esta tentando gravar o arquivo usando o retorno de um item.getName(). Como voce nao fez verificacao de consistencia, vai levar um NPE mesmo :mrgreen:
O que acontece eh que o IE manda o nome completo do arquivo (com o path e tudo mais). Ou seja, se vc pegou o arquivo em c:\documentos\relatorio_mensal.doc, uma chamada a item.getName() vai retornar exatamente “c:\documentos\relatorio_mensal.doc”, enquanto nos outros browsers vai vir apenas “relatorio_mensal.doc”.
A solucao eh voce fazer uns ifs() substrings() para pegar apenas o nome “real” do arquivo enviado.
Rafael
Eu faço upload com o código abaixo,
vê se te ajuda…
public String realizaUpload(HttpServletRequest request)
{
String retorno = "";
try
{
String contentType = request.getContentType();
if (( contentType != null )&&( contentType.indexOf( "multipart/form-data" ) >= 0 ))
{
DataInputStream in = new DataInputStream( request.getInputStream() );
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[ formDataLength ];
int byteRead = 0;
int totalBytesRead = 0;
while ( totalBytesRead < formDataLength )
{
byteRead = in.read( dataBytes, totalBytesRead, formDataLength );
totalBytesRead += byteRead;
}
String file = new String( dataBytes );
String saveFile = file.substring( file.indexOf( "filename=\"" ) + 10 );
saveFile = saveFile.substring( 0, saveFile.indexOf( "\n" ) );
saveFile = saveFile.substring( saveFile.lastIndexOf( "\\" ) + 1, saveFile.indexOf( "\"" ) );
int lastIndex = contentType.lastIndexOf( "=" );
String boundary = contentType.substring( lastIndex + 1, contentType.length() );
int pos;
pos = file.indexOf( "filename=\"" );
pos = file.indexOf( "\n", pos ) + 1;
pos = file.indexOf( "\n", pos ) + 1;
pos = file.indexOf( "\n", pos ) + 1;
int boundaryLocation = file.indexOf( boundary, pos ) - 4;
int startPos = ( ( file.substring( 0, pos ) ).getBytes() ).length;
int endPos = ( ( file.substring( 0, boundaryLocation ) ).getBytes() ).length;
retorno = "c:/local_do_upload/"+saveFile;
FileOutputStream fileOut = new FileOutputStream( retorno );
fileOut.write( dataBytes, startPos, ( endPos - startPos ) );
fileOut.flush();
fileOut.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
return retorno;
}