List of usage examples for org.apache.commons.fileupload FileItem getSize
long getSize();
From source file:com.jkingii.web.files.upload.java
/** * Processes requests for both HTTP// ww w . ja v a 2s .c o m * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Check that we have a file upload request isMultipart = ServletFileUpload.isMultipartContent(request); FileDataBase fdb = null; response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { CSession cSession = (CSession) request.getSession().getAttribute("cSession"); if (!isMultipart) { out.println("<html>"); out.println("<head>"); out.println("<title>Servlet upload</title>"); out.println("</head>"); out.println("<body>"); out.println("<p>No file uploaded</p>"); out.println("</body>"); out.println("</html>"); return; } DiskFileItemFactory factory = new DiskFileItemFactory(); // maximum size that will be stored in memory factory.setSizeThreshold(maxMemSize); // Location to save data that is larger than maxMemSize. factory.setRepository(new File(tempDir)); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // maximum file size to be uploaded. upload.setSizeMax(maxFileSize); // Parse the request to get file items. List fileItems = upload.parseRequest(request); // Se verifica si el usuario tiene permisos de escritura. ColumnasPermisos permiso = checkPermisos(request, fileItems, out); if (permiso == null) { return; } // Process the uploaded file items Iterator i = fileItems.iterator(); while (i.hasNext()) { FileItem fi = (FileItem) i.next(); MessageDigest md5 = MessageDigest.getInstance("MD5"); if (!fi.isFormField()) { // Get the uploaded file parameters logger.info("Prosess Request: obteniendo session: [" + cSession + "] jsessionid = [" + request.getSession().getId() + "]", this); fdb = new FileDataBase(GenKey.newKey(), cSession.getAccessInfo().getEmpresa(), cSession.getAccessInfo().getUserInfo(), new Date().getTime(), fi.getName(), new MimeType().factory().getMime(fi.getName(), fi.get()), fi.get(), Hexadecimal.getHex(md5.digest(fi.get())), fi.getSize(), permiso); fileDataBaseFacade.create(fdb); } } ResponseConfig config = new ResponseConfig(); config.setTimeZone(cSession.getAccessInfo().getTimeZone()); out.println(fdb.toJson(config)); } catch (FileUploadException | NoSuchAlgorithmException e) { logger.error("Error cargando el fichero en el servidor, " + "Exception: {}", e.getMessage()); } catch (UnknownColumnException e) { logger.error("Imposible la columna para el link debe existir referer[{}], " + "p[{}]", request.getHeader("referer"), request.getParameter(PERMISO_FIELD)); logger.debug("referrer: " + request.getHeader("referrer")); } finally { out.close(); } }
From source file:com.dien.upload.server.UploadServlet.java
protected Map<String, String> getFileItemsSummary(HttpServletRequest request, Map<String, String> ret) { if (ret == null) { ret = new HashMap<String, String>(); }/*from ww w. ja v a 2 s. co m*/ @SuppressWarnings("unchecked") List<FileItem> s = (List<FileItem>) request.getSession().getAttribute(SESSION_LAST_FILES); if (s != null) { for (FileItem i : s) { if (false == i.isFormField()) { ret.put("ctype", i.getContentType() != null ? i.getContentType() : "unknown"); ret.put("size", "" + i.getSize()); ret.put("name", "" + i.getName()); ret.put("field", "" + i.getFieldName()); } } ret.put(TAG_FINISHED, "ok"); } return ret; }
From source file:com.duroty.application.mail.actions.SaveDraftAction.java
protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ActionMessages errors = new ActionMessages(); try {//from ww w . j a va 2 s . c om boolean isMultipart = FileUpload.isMultipartContent(request); if (isMultipart) { Map fields = new HashMap(); Vector attachments = new Vector(); //Parse the request List items = diskFileUpload.parseRequest(request); //Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { fields.put(item.getFieldName(), item.getString()); } else { if (!StringUtils.isBlank(item.getName())) { ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); IOUtils.copy(item.getInputStream(), baos); MailPartObj part = new MailPartObj(); part.setAttachent(baos.toByteArray()); part.setContentType(item.getContentType()); part.setName(item.getName()); part.setSize(item.getSize()); attachments.addElement(part); } catch (Exception ex) { } finally { IOUtils.closeQuietly(baos); } } } } String body = ""; if (fields.get("taBody") != null) { body = (String) fields.get("taBody"); } else if (fields.get("taReplyBody") != null) { body = (String) fields.get("taReplyBody"); } Preferences preferencesInstance = getPreferencesInstance(request); Send sendInstance = getSendInstance(request); String mid = (String) fields.get("mid"); sendInstance.saveDraft(mid, Integer.parseInt((String) fields.get("identity")), (String) fields.get("to"), (String) fields.get("cc"), (String) fields.get("bcc"), (String) fields.get("subject"), body, attachments, preferencesInstance.getPreferences().isHtmlMessage(), Charset.defaultCharset().displayName(), (String) fields.get("priority")); } else { errors.add("general", new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "mail.send", "The form is null")); request.setAttribute("exception", "The form is null"); request.setAttribute("newLocation", null); doTrace(request, DLog.ERROR, getClass(), "The form is null"); } } catch (Exception ex) { String errorMessage = ExceptionUtilities.parseMessage(ex); if (errorMessage == null) { errorMessage = "NullPointerException"; } errors.add("general", new ActionMessage(ExceptionCode.ERROR_MESSAGES_PREFIX + "general", errorMessage)); request.setAttribute("exception", errorMessage); doTrace(request, DLog.ERROR, getClass(), errorMessage); } finally { } if (errors.isEmpty()) { doTrace(request, DLog.INFO, getClass(), "OK"); return mapping.findForward(Constants.ACTION_SUCCESS_FORWARD); } else { saveErrors(request, errors); return mapping.findForward(Constants.ACTION_FAIL_FORWARD); } }
From source file:com.wellmail.servlet.ConnectorServlet.java
/** * Manage the <code>POST</code> requests (<code>FileUpload</code>).<br /> * //from w w w. j a va 2 s. co m * The servlet accepts commands sent in the following format:<br /> * <code>connector?Command=<FileUpload>&Type=<ResourceType>&CurrentFolder=<FolderPath></code> * with the file in the <code>POST</code> body.<br /> * <br> * It stores an uploaded file (renames a file if another exists with the * same name) and then returns the JavaScript callback. */ @SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("Entering Connector#doPost"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); logger.debug("Parameter Command: {}", commandStr); logger.debug("Parameter Type: {}", typeStr); logger.debug("Parameter CurrentFolder: {}", currentFolderStr); UploadResponse ur; // if this is a QuickUpload request, 'commandStr' and 'currentFolderStr' // are empty if (Utils.isEmpty(commandStr) && Utils.isEmpty(currentFolderStr)) { commandStr = "QuickUpload"; currentFolderStr = "/"; } if (!RequestCycleHandler.isEnabledForFileUpload(request)) ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR, null, null, Messages.NOT_AUTHORIZED_FOR_UPLOAD); else if (!CommandHandler.isValidForPost(commandStr)) ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_COMMAND); else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr)) ur = new UploadResponse(UploadResponse.SC_ERROR, null, null, Messages.INVALID_TYPE); else if (!UtilsFile.isValidPath(currentFolderStr)) ur = UploadResponse.UR_INVALID_CURRENT_FOLDER; else { ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr); String typePath = UtilsFile.constructServerSidePath(request, resourceType); String typeDirPath = getServletContext().getRealPath(typePath); File typeDir = new File(typeDirPath); UtilsFile.checkDirAndCreate(typeDir); File currentDir = new File(typeDir, currentFolderStr); if (!currentDir.exists()) ur = UploadResponse.UR_INVALID_CURRENT_FOLDER; else { String newFilename = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("UTF-8"); try { List<FileItem> items = upload.parseRequest(request); // We upload only one file at the same time FileItem uplFile = items.get(0); String rawName = UtilsFile.sanitizeFileName(uplFile.getName()); String filename = FilenameUtils.getName(rawName); String baseName = FilenameUtils.removeExtension(filename); String extension = FilenameUtils.getExtension(filename); filename = UUID.randomUUID().toString() + "." + extension; if (!ExtensionsHandler.isAllowed(resourceType, extension)) ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION); //20k else if (uplFile.getSize() > 100 * 1024) { ur = new UploadResponse(204); } else { // construct an unique file name File pathToSave = new File(currentDir, filename); int counter = 1; while (pathToSave.exists()) { newFilename = baseName.concat("(").concat(String.valueOf(counter)).concat(")") .concat(".").concat(extension); pathToSave = new File(currentDir, newFilename); counter++; } if (Utils.isEmpty(newFilename)) ur = new UploadResponse(UploadResponse.SC_OK, UtilsResponse.constructResponseUrl(request, resourceType, currentFolderStr, true, ConnectorHandler.isFullUrl()).concat(filename)); else ur = new UploadResponse(UploadResponse.SC_RENAMED, UtilsResponse.constructResponseUrl(request, resourceType, currentFolderStr, true, ConnectorHandler.isFullUrl()).concat(newFilename), newFilename); // secure image check if (resourceType.equals(ResourceTypeHandler.IMAGE) && ConnectorHandler.isSecureImageUploads()) { if (UtilsFile.isImage(uplFile.getInputStream())) uplFile.write(pathToSave); else { uplFile.delete(); ur = new UploadResponse(UploadResponse.SC_INVALID_EXTENSION); } } else uplFile.write(pathToSave); } } catch (Exception e) { ur = new UploadResponse(UploadResponse.SC_SECURITY_ERROR); } } } out.print(ur); out.flush(); out.close(); logger.debug("Exiting Connector#doPost"); }
From source file:com.gwtcx.server.servlet.FileUploadServlet.java
@SuppressWarnings("rawtypes") private void processFiles(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // set the size threshold, above which content will be stored on disk factory.setSizeThreshold(1 * 1024 * 1024); // 1 MB // set the temporary directory (this is where files that exceed the threshold will be stored) factory.setRepository(tmpDir);// ww w . j a v a 2 s .c o m // create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); try { String recordType = "Account"; // parse the request List items = upload.parseRequest(request); // process the uploaded items Iterator itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); // process a regular form field if (item.isFormField()) { Log.debug("Field Name: " + item.getFieldName() + ", Value: " + item.getString()); if (item.getFieldName().equals("recordType")) { recordType = item.getString(); } } else { // process a file upload Log.debug("Field Name: " + item.getFieldName() + ", Value: " + item.getName() + ", Content Type: " + item.getContentType() + ", In Memory: " + item.isInMemory() + ", File Size: " + item.getSize()); // write the uploaded file to the application's file staging area File file = new File(destinationDir, item.getName()); item.write(file); // import the CSV file importCsvFile(recordType, file.getPath()); // file.delete(); // TO DO } } } catch (FileUploadException e) { Log.error("Error encountered while parsing the request", e); } catch (Exception e) { Log.error("Error encountered while uploading file", e); } }
From source file:edu.emory.cci.aiw.cvrg.eureka.servlet.JobSubmitServlet.java
private Long submitJob(HttpServletRequest request, Principal principal) throws FileUploadException, IOException, ClientException, ParseException { DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(); /*//from w ww.j a va 2s . co m *Set the size threshold, above which content will be stored on disk. */ fileItemFactory.setSizeThreshold(5 * 1024 * 1024); //5 MB /* * Set the temporary directory to store the uploaded files of size above threshold. */ fileItemFactory.setRepository(this.tmpDir); ServletFileUpload uploadHandler = new ServletFileUpload(fileItemFactory); /* * Parse the request */ List items = uploadHandler.parseRequest(request); Properties fields = new Properties(); for (Iterator itr = items.iterator(); itr.hasNext();) { FileItem item = (FileItem) itr.next(); /* * Handle Form Fields. */ if (item.isFormField()) { fields.setProperty(item.getFieldName(), item.getString()); } } JobSpec jobSpec = MAPPER.readValue(fields.getProperty("jobSpec"), JobSpec.class); for (Iterator itr = items.iterator(); itr.hasNext();) { FileItem item = (FileItem) itr.next(); if (!item.isFormField()) { //Handle Uploaded files. log("Spreadsheet upload for user " + principal.getName() + ": Field Name = " + item.getFieldName() + ", File Name = " + item.getName() + ", Content type = " + item.getContentType() + ", File Size = " + item.getSize()); if (item.getSize() > 0) { InputStream is = item.getInputStream(); try { this.servicesClient.upload(FilenameUtils.getName(item.getName()), jobSpec.getSourceConfigId(), item.getFieldName(), is); log("File '" + item.getName() + "' uploaded successfully"); } finally { if (is != null) { try { is.close(); } catch (IOException ignore) { } } } } else { log("File '" + item.getName() + "' ignored because it was zero length"); } } } URI uri = this.servicesClient.submitJob(jobSpec); String uriStr = uri.toString(); Long jobId = Long.valueOf(uriStr.substring(uriStr.lastIndexOf("/") + 1)); log("Job " + jobId + " submitted for user " + principal.getName()); return jobId; }
From source file:com.sr.model.dao.IMahasiswaDAOImpl.java
@Override public boolean insertBiodata(Mahasiswa mhs, AkademikSR aka, FileItem foto, List<Prestasi> prestasi) { try {/*from www. java 2 s. co m*/ LobHandler lobHandler = new DefaultLobHandler(); getJdbcTemplate().update(INSERT_BIODATA, new Object[] { mhs.getNamaMhs(), mhs.getTempat_lahir(), mhs.getTanggal_lahir(), mhs.getAgama(), mhs.getKelamin(), mhs.getAlamat_asal(), mhs.getKab_kota_asal(), mhs.getProv_asal(), mhs.getNo_hp_mhs(), mhs.getNama_ayah(), mhs.getNama_ibu(), mhs.getPendidikan_ayah(), mhs.getPendidikan_ibu(), mhs.getPekerjaan_ayah(), mhs.getPekerjaan_ibu(), mhs.getPendapatan_ortu(), mhs.getNo_tel_ortu(), mhs.getNo_hp_ortu(), mhs.getAlamat_keluarga(), mhs.getNo_tel_keluarga(), mhs.getNo_hp_keluarga(), new SqlLobValue(foto.getInputStream(), (int) foto.getSize(), lobHandler), mhs.getNim() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.NUMERIC, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR }); getJdbcTemplate().update(INSERT_AKADEMIK, new Object[] { aka.getProdi(), aka.getIpk_masuk(), aka.getSemester(), aka.getRapor_smu(), aka.getJurusan(), aka.getFakultas(), aka.getNim() }, new int[] { Types.VARCHAR, Types.DECIMAL, Types.NUMERIC, Types.DECIMAL, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR }); for (Prestasi pres : prestasi) { getJdbcTemplate().update(INSERT_PRESTASI, new Object[] { pres.getNo_sertifikat(), pres.getNim(), pres.getNama_prestasi(), pres.getJenis_prestasi() }); } return true; } catch (DataAccessException da) { System.out.println("DataAccessException" + da.getMessage()); } catch (FileNotFoundException ex) { System.out.println("FileNotFoundException " + ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } return false; }
From source file:it.eng.spagobi.tools.importexport.services.ManageImpExpAssAction.java
private void uploadAssHandler(SourceBean sbrequest) { logger.debug("IN"); try {//from w w w . j av a 2s. c om String modality = "MANAGE"; String name = (String) sbrequest.getAttribute("NAME"); if (name == null || name.trim().equals("")) { String msg = msgBuild.getMessage("Sbi.saving.nameNotSpecified", "component_impexp_messages", locale); httpResponse.getOutputStream().write(msg.getBytes()); httpResponse.getOutputStream().flush(); return; } String description = (String) sbrequest.getAttribute("DESCRIPTION"); if (description == null) description = ""; // UploadedFile uplFile = (UploadedFile)sbrequest.getAttribute("UPLOADED_FILE"); FileItem uplFile = (FileItem) sbrequest.getAttribute("UPLOADED_FILE"); byte[] content = null; if (uplFile == null || uplFile.getName().trim().equals("")) { String msg = msgBuild.getMessage("Sbi.saving.associationFileNotSpecified", "component_impexp_messages", locale); httpResponse.getOutputStream().write(msg.getBytes()); httpResponse.getOutputStream().flush(); return; } else { if (uplFile.getSize() == 0) { String msg = msgBuild.getMessage("201", "component_impexp_messages", locale); httpResponse.getOutputStream().write(msg.getBytes()); httpResponse.getOutputStream().flush(); return; } int maxSize = GeneralUtilities.getTemplateMaxSize(); if (uplFile.getSize() > maxSize) { String msg = msgBuild.getMessage("202", "component_impexp_messages", locale); httpResponse.getOutputStream().write(msg.getBytes()); httpResponse.getOutputStream().flush(); return; } content = uplFile.get(); if (!AssociationFile.isValidContent(content)) { String msg = msgBuild.getMessage("Sbi.saving.associationFileNotValid", "component_impexp_messages", locale); httpResponse.getOutputStream().write(msg.getBytes()); httpResponse.getOutputStream().flush(); return; } } String overwriteStr = (String) sbrequest.getAttribute("OVERWRITE"); boolean overwrite = (overwriteStr == null || overwriteStr.trim().equals("")) ? false : Boolean.parseBoolean(overwriteStr); AssociationFile assFile = new AssociationFile(); assFile.setDescription(description); assFile.setName(name); assFile.setDateCreation(new Date().getTime()); assFile.setId(name); IAssociationFileDAO assfiledao = new AssociationFileDAO(); if (assfiledao.exists(assFile.getId())) { if (overwrite) { assfiledao.deleteAssociationFile(assFile); assfiledao.saveAssociationFile(assFile, content); } else { logger.warn("Overwrite parameter is false: association file with id=[" + assFile.getId() + "] " + "and name=[" + assFile.getName() + "] will not be saved."); } } else { assfiledao.saveAssociationFile(assFile, content); } List assFiles = assfiledao.getAssociationFiles(); String html = generateHtmlJsCss(); html += "<br/>"; html += generateHtmlForInsertNewForm(); html += "<br/>"; html += generateHtmlForList(assFiles, modality); httpResponse.getOutputStream().write(html.getBytes()); httpResponse.getOutputStream().flush(); } catch (Exception e) { logger.error("Error while saving the association file, ", e); } finally { logger.debug("OUT"); } }
From source file:it.infn.ct.mpi_portlet.java
public void getInputForm(ActionRequest request) { if (PortletFileUpload.isMultipartContent(request)) try {// www .j av a 2 s . co m FileItemFactory factory = new DiskFileItemFactory(); PortletFileUpload upload = new PortletFileUpload(factory); List items = upload.parseRequest(request); File repositoryPath = new File("/tmp"); DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(); diskFileItemFactory.setRepository(repositoryPath); Iterator iter = items.iterator(); String logstring = ""; while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); String fieldName = item.getFieldName(); String fileName = item.getName(); String contentType = item.getContentType(); boolean isInMemory = item.isInMemory(); long sizeInBytes = item.getSize(); logstring += LS + "field name: '" + fieldName + "' - '" + item.getString() + "'"; switch (inputControlsIds.valueOf(fieldName)) { case file_inputFile: inputFileName = item.getString(); processInputFile(item); break; case inputFile: inputFileText = item.getString(); break; case JobIdentifier: jobIdentifier = item.getString(); break; case cpunumber: cpunumber = item.getString(); break; default: _log.info("Unhandled input field: '" + fieldName + "' - '" + item.getString() + "'"); } // switch fieldName } // while iter.hasNext() _log.info(LS + "Reporting" + LS + "---------" + LS + logstring); } catch (Exception e) { _log.info("Caught exception while processing files to upload: '" + e.toString() + "'"); } // The input form do not use the "multipart/form-data" else { // Retrieve from the input form the given application values inputFileName = (String) request.getParameter("file_inputFile"); inputFileText = (String) request.getParameter("inputFile"); jobIdentifier = (String) request.getParameter("JobIdentifier"); cpunumber = (String) request.getParameter("cpunumber"); } // ! isMultipartContent // Show into the log the taken inputs _log.info(LS + "Taken input parameters:" + LS + "inputFileName: '" + inputFileName + "'" + LS + "inputFileText: '" + inputFileText + "'" + LS + "jobIdentifier: '" + jobIdentifier + "'" + LS + "cpunumber: '" + cpunumber + "'"); }
From source file:it.lufraproini.cms.servlet.Upload.java
private Immagine memorizzaImmagine(Map data, CMSDataLayerImpl datalayer, String digest, long id_user) throws SQLException, ErroreGrave { String error_message;/*w w w. j a v a 2 s.com*/ Map files = new HashMap(); FileItem fi = null; files = (HashMap) data.get("files"); fi = (FileItem) files.get("file_to_upload"); /*costruzione current timestamp*/ Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); Timestamp current_timestamp = new Timestamp(now.getTime()); /**/ Utente U = datalayer.getUtente(id_user); Immagine img_upload = datalayer.createImmagine(); Immagine img_result; //se l'utente non ha spazio a sufficienza per fare l'upload questo viene rifiutato long spazio_risultante = U.getSpazio_disp_img() - fi.getSize(); if (spazio_risultante < 0) { //viene eliminato il file appena memorizzato in action_upload File uploaded_file = new File( getServletContext().getRealPath(getServletContext().getInitParameter("system.image_directory")) + File.separatorChar + this.nomefile + "." + this.estensione); if (uploaded_file.exists()) { uploaded_file.delete(); } error_message = "L'utente non ha spazio disponibile sufficiente per caricare l'immagine!"; error_message += " Byte disponibili: " + U.getSpazio_disp_img(); error_message += " - Byte immagine: " + fi.getSize(); throw new ErroreGrave(error_message); } img_upload.setNome(SecurityLayer.addSlashes(data.get("nome").toString())); img_upload.setDimensione(fi.getSize()); img_upload.setTipo(fi.getContentType()); img_upload.setFile(getServletContext().getInitParameter("system.image_directory") + File.separatorChar + digest + "." + estensione); img_upload.setDigest(digest); img_upload.setData_upload(current_timestamp); img_upload.setUtente(U); img_result = datalayer.addImmagine(img_upload); // aggiornamento spazio immagini utente if (img_result != null) { U.setSpazio_disp_img(spazio_risultante); U = datalayer.updateUtente(U); if (U != null) { return img_result; } else { datalayer.deleteImmagine(img_result); throw new ErroreGrave("Non stato possibile aggiornare lo spazio immagine dell'utente!"); } } throw new ErroreGrave("Impossibile inserire i dati dell'immagine nel DB!"); }