1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
fileItemFactory.setSizeThreshold(1 * 1024 * 1024); //1 MB
fileItemFactory.setRepository(tmpDir);
ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory);
FileItem item = null;
File myFile = null;
try {
List items = uploadHandler.parseRequest(request);
Iterator itr = items.iterator();
while (itr.hasNext()) {
item = (FileItem) itr.next();
myFile= new File(destinationDir, item.getName());
myFile.setWritable(true);
item.write(file);
//Traitement back-end pour créer un fichier zip à partir de myFile
uploadFile(idTask, file, mimeType, new Long(propertiesOpCrm.getProperty("idTable")), connectedUser.getLogin(), idPatient, new Long(propertiesOpCrm.getProperty("idDescription")));
myFile.delete();
catch (FileUploadException ex) {
log("Error encountered while parsing the request", ex);
} catch (Exception ex) {
log("Error encountered while parsing the request", ex);
} finally {
if (out != null) out.close();
if (item != null) item.delete();
if(myFile != null) myFile.delete();
} |
Partager