Boa noite!
Tenho o seguinte arquivo:
index.jsp
<body>
<form action="TesteServlet" method="post">
<input type="file" name="imagem"/>
<input type="submit" name="bt" value="Pressione"/>
</form>
</body>
A classe TesteServlet.java simplesmente armazena a imagem no banco de dados.
E isso funciona perfeitamente quando executado no eclipse.
Quando porém, executo no IE ou ainda no Google Chrome, é lançado IOException
com a seguinte mensagem: Can’t read input file!.
Seria algo relacionado a permissão?
Como resolver o problema?
Amigo, posso lhe perguntar como você está fazendo a recuperação deste arquivo?
[quote=ganondorfan]Amigo, posso lhe perguntar como você está fazendo a recuperação deste arquivo?
[/quote]
A recuperação é feita através do :
<input type="file" name="imagem"/>
TesteServlet.java
...
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String imagem = request.getParameter("imagem");
gravar( imagem );
}
private void gravar( String imagem )
{
try
{
//URL url = this.getClass().getResource("paliofire.jpg");
File file = new File( imagem );
BufferedImage img = ImageIO.read( file );
ByteArrayOutputStream b = new ByteArrayOutputStream();
ImageIO.write( img, "jpg", b );
byte[] imgByte = b.toByteArray();
String sql = "INSERT INTO tb_imagens VALUES( NULL, ? )";
PreparedStatement stm = Conexao.getConexao().prepareStatement(sql);
stm.setBytes(1, imgByte);
stm.execute();
stm.close();
System.out.println( "gravado!" );
}
catch( SQLException e )
{
e.printStackTrace();
throw new RuntimeException( e.getMessage() );
}
catch( IOException ex )
{
ex.printStackTrace();
throw new RuntimeException( ex.getMessage() );
}
}