eu tenho um sistema de upload, ele esta funcionando, mais nao sei como fazer para varias fotos de uma soh vez
codigo do html:
codigo do jsp:
<jsp:useBean id="info" class="classes.Funcoes"></jsp:useBean>
<% //verifica se o usuarios esta logado
if (session.getAttribute("AdmLogado") == null){
response.sendRedirect("VerificaJs.html");
}else{
//verifica a sesion com o id do albun
if (session.getAttribute("album") != null){
info.conecta();
//aqui ele envia para fazer o upload
info.uploadImagem(session,request);
info.desconecta();
response.sendRedirect("VerAlbumAdm.jsp?album="+session.getAttribute("album")+"&OK=upload");
}else{
response.sendRedirect("IndexAdm.jsp");
}
}
%>
metodo que faz o upload:
public void uploadImagem(HttpSession session,ServletRequest request){
try {
String savePath = enderecoSistema+ mostraNomeAlbumUrl(Integer.parseInt(session.getAttribute("album").toString())) + "\\normal\\";
String nomeFoto = session.getAttribute("album").toString()+"_"+mostraIdFoto();
String filename = "";
ServletInputStream in = request.getInputStream();
byte[] line = new byte[128];
int i = in.readLine(line, 0, 128);
int boundaryLength = i - 2;
String boundary = new String(line, 0, boundaryLength);
ByteArrayOutputStream buffer = null;
String idFoto = mostraIdFoto();
while (i != -1) {
String newLine = new String(line, 0, i);
if (newLine.startsWith("Content-Disposition: form-data; name=\"")) {
String s = new String(line, 0, i - 2);
int pos = s.indexOf("filename=\"");
if (pos != -1) {
String filepath = s.substring(pos + 10, s.length() - 1);
pos = filepath.lastIndexOf("\\");
if (pos != -1)
filename = filepath.substring(pos + 1);
else
filename = filepath;
}
i = in.readLine(line, 0, 128);
i = in.readLine(line, 0, 128);
i = in.readLine(line, 0, 128);
buffer = new ByteArrayOutputStream();
newLine = new String(line, 0, i);
while (i != -1 && !newLine.startsWith(boundary)) {
buffer.write(line, 0, i);
i = in.readLine(line, 0, 128);
newLine = new String(line, 0, i);
}
//pega a extencao do arquivo
String extencao = filename.substring(filename.lastIndexOf("."));
filename = nomeFoto+extencao;
//salva no banco
String nomeFotoSession = "";
if (session.getAttribute("nomeFoto") != null){
nomeFotoSession = session.getAttribute("nomeFoto").toString();
}
criaVotacaoFoto(idFoto,session.getAttribute("album").toString());
gravaFoto(mostraIdFoto(),mostraNomeAlbumUrl(Integer.parseInt(session.getAttribute("album").toString())) + "/normal/"+filename,Integer.parseInt(session.getAttribute("album").toString()),nomeFotoSession);
//salva arquivo
RandomAccessFile f = new RandomAccessFile(savePath+ filename, "rw");
try {
byte[] bytes = buffer.toByteArray();
f.write(bytes, 0, bytes.length - 2);
} catch (Exception e) {
}finally{
f.close();
}
}
i = in.readLine(line, 0, 128);
} // end while
in.close();
buffer.close();
geraFotoMiniatura(enderecoSistema+mostraNomeAlbumUrl(Integer.parseInt(session.getAttribute("album").toString())) + "/normal/"+filename,enderecoSistema+mostraNomeAlbumUrl(Integer.parseInt(session.getAttribute("album").toString())) + "/miniatura/"+filename);
} catch (IOException e1) {
System.out.println(e1.getMessage());
}
}
se puderem me dar uma ideia de como fazer upload de varias fotos ao mesmo tempo