Boa noite!
Estou usando os seguites códigos para fazer o upload de um arquivo:
<h:form enctype="multipart/form-data">
<font size="3" color="#0066CC"><b>Apresentação do negócio:</b></font><hr/>
<t:inputFileUpload storage="file" value="#{NovoNegocioBean.logomarca}"/>
<h:commandButton action="#{NovoNegocio.CriaNegocio}"/>
</h:form>
public String CriaNegocio () {
FacesContext ctx = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext)ctx.getExternalContext().getContext();
//no contexto web, deverá existir uma pasta chamada temp
String path = servletContext.getRealPath("/temp");
String arquivo = Logomarca.getName();
//local onde será gravado o arquivo no contexto web (o arquivo será renomeado para teste.txt)
//isto dentro da pasta (contexto)/temp
String fullPath = path + "/teste.txt";
String contentType = Logomarca.getContentType();
ctx.getExternalContext().getApplicationMap().put("fileupload_type", contentType);
ctx.getExternalContext().getApplicationMap().put("fileupload_name", arquivo);
File file = new File(fullPath);
BufferedInputStream bufferedInputStream = null;
FileOutputStream fileOutputStream = null;
// Salvando o arquivo
try {
bufferedInputStream = new BufferedInputStream(Logomarca.getInputStream());
fileOutputStream = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int count;
while ((count = bufferedInputStream.read(buffer)) > 0)
fileOutputStream.write(buffer, 0, count);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bufferedInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
O upload é feito corretamente. O que eu queria é saber como eu faço pra descobrir algumas propriedades do arquivo antes de eu fazer o upload.
No caso estou trabalhando com imagens JPEG e gostaria de saber as dimensões da imagem (width / height) e tamanho (Kb).
Alguém saberia me falar como faço isso?
Muito obrigado!
Abraço, Bottoni