2
How to recover the file name saved as BLOB from the database and display on screen? I am using a loop, to recover, the value saved in the database column, but returns memory values ([B@2248bd40):
Another inconsistency that is occurring is: When the user performs the Upload to the database, the file is saved successfully (any file), but to run the donwload I must inform the code, and only allows the output of the file in the extension formatted in the source code (Example: pdf, doc, etc.). The problem is, it will only come out according to the defined extension. It has some way to run the donwload of the file in original format, which has been saved?
Follows the method:
public void download() {
ResultSet rs;
try {
Connection con = Conexao.getConnection();
PreparedStatement st = con.prepareStatement("SELECT image FROM uploadfile WHERE codigo = (?) ");
st.setInt(1, codigo);
rs = st.executeQuery();
while (rs.next()) {
InputStream stream = rs.getBinaryStream("image");
file = new DefaultStreamedContent(stream, "image/jpg", "Arquivo.pdf");
}
con.close();
FacesMessage message = new FacesMessage("Exito", " File descarregado com sucesso.");
FacesContext.getCurrentInstance().addMessage(null, message);
} catch (Exception erro) {
erro.printStackTrace();
FacesMessage message = new FacesMessage("Erro ao executar download.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
Do you need to store the files in the database? Can’t you save them in some Torage or something? In the database just save the file path. I personally find it much easier.
– igventurelli