List of usage examples for org.apache.commons.fileupload DefaultFileItem getName
public String getName()
From source file:ca.myewb.frame.PostParamWrapper.java
public boolean saveJpeg(String name, int userid) throws Exception { DefaultFileItem item = ((DefaultFileItem) fileParams.get(name)); if (item.getName().equals("")) { return false; }//ww w . j av a2s .c o m String userIdStr = Integer.toString(userid); String userPicturesDir = Helpers.getUserPicturesDir(); String fullPath = userPicturesDir + "/fullsize/" + userIdStr + ".jpg"; String thumbPath = userPicturesDir + "/thumbs/" + userIdStr + ".jpg"; String minithumbPath = userPicturesDir + "/minithumbs/" + userIdStr + ".jpg"; String screenPath = userPicturesDir + "/screensize/" + userIdStr + ".jpg"; File file = new File(fullPath); File thumbnail = new File(thumbPath); File minithumbnail = new File(minithumbPath); File screensize = new File(screenPath); try { file.delete(); item.write(file); String command = ""; thumbnail.delete(); command = "convert -thumbnail 200x200 -quality 100 " + fullPath + " " + thumbPath; Runtime.getRuntime().exec(command).waitFor(); if (!thumbnail.exists()) { throw new Exception("no file: " + thumbPath); } minithumbnail.delete(); command = "convert -thumbnail 75x -quality 100 " + fullPath + " " + minithumbPath; Runtime.getRuntime().exec(command).waitFor(); if (!minithumbnail.exists()) { throw new Exception("no file: " + minithumbPath); } screensize.delete(); command = "convert -thumbnail 800x600 -quality 100 " + fullPath + " " + screenPath; Runtime.getRuntime().exec(command).waitFor(); if (!screensize.exists()) { throw new Exception("no file: " + screenPath); } return true; } catch (Exception e) { Logger.getLogger(this.getClass()).error("jpeg error: " + e, e); file.delete(); thumbnail.delete(); minithumbnail.delete(); return false; } }
From source file:ca.myewb.frame.PostParamWrapper.java
public void saveFile(String fieldPrefix, String subpath) throws Exception { for (String fileName : fileParams.keySet()) { log.info("Attempting to upload file from field: " + fileName); //subpath must be of form a/b/c not /a/b/c/ if (fileParams.get(fileName) != null && fileName.regionMatches(0, fieldPrefix, 0, fieldPrefix.length())) { String[] dirs = subpath.split("/"); String current = ""; for (int i = 0; i < dirs.length; i++) { File currentSubDir = (new File(Helpers.getUserFilesDir() + current + "/" + dirs[i])); if (!currentSubDir.exists()) { currentSubDir.mkdir(); log.info("Directory " + currentSubDir.getPath() + " created."); }/*from w w w . ja v a2s .c o m*/ current += ("/" + dirs[i]); } DefaultFileItem item = ((DefaultFileItem) fileParams.get(fileName)); String prepath = Helpers.getUserFilesDir() + "/" + subpath + "/"; safeFileReplace(new File(prepath + makeNormalFileName(item.getName())), item); log.info("Successfully uploaded " + item.getName()); Helpers.currentDailyStats().logFilesAdded(); } } }
From source file:sos.settings.SOSSettingsDialog.java
private void checkRequest() throws Exception { this.debug(3, "checkRequest"); this.settings.sources.put(this.settings.source, this.dialogApplicationsTitle); this.settings.application = ""; this.settings.section = ""; this.settings.entry = ""; this.inputQuery = ""; this.inputExport = ""; this.inputImport = ""; this.importOriginalFileName = ""; // Daten aus fileUpload LinkedHashMap requestMultipart = new LinkedHashMap(); if (this.request != null) { ///////////////////////////////////////////////////////// String contentType = this.request.getHeader("Content-type"); if (contentType != null && contentType.startsWith("multipart/")) { // ob Import try { DiskFileUpload upload = new DiskFileUpload(); upload.setSizeMax(this.importMaxSize); upload.setSizeThreshold(0); // nicht im Memory sondern als // Datei speichern List items = upload.parseRequest(this.request); Iterator iter = items.iterator(); while (iter.hasNext()) { //FileItem item = (FileItem) iter.next(); DefaultFileItem item = (DefaultFileItem) iter.next(); if (item.isFormField()) { requestMultipart.put(item.getFieldName(), item.getString()); this.request.setAttribute(item.getFieldName(), item.getString()); } else { // aus upload if (item.getName() != null && !item.getName().equals("")) { //requestMultipart.put(item.getFieldName(),item.getStoreLocation()); requestMultipart.put(item.getFieldName(), item.getStoreLocation().getAbsolutePath()); this.request.setAttribute(item.getFieldName(), item.getStoreLocation().getAbsolutePath()); this.importOriginalFileName = item.getName(); } else { requestMultipart.put(item.getFieldName(), ""); this.request.setAttribute(item.getFieldName(), ""); }/*from w w w.j a v a2 s . co m*/ } } } catch (FileUploadException e) { this.setError(e.getMessage(), SOSClassUtil.getMethodName()); } } // MULTIPART Form ///////////////////////////////////////////////////////// if (this.getRequestValue("application") != null) { this.settings.application = this.getRequestValue("application"); } if (this.getRequestValue("section") != null) { this.settings.section = this.getRequestValue("section"); } if (this.getRequestValue("entry") != null) { this.settings.entry = this.getRequestValue("entry"); } if (this.getRequestValue("application_type") != null) { try { this.applicationType = Integer.parseInt(this.getRequestValue("application_type")); } catch (Exception e) { this.applicationType = 0; } } if (this.getRequestValue("section_type") != null) { try { this.sectionType = Integer.parseInt(this.getRequestValue("section_type")); } catch (Exception e) { this.sectionType = 0; } } if (this.getRequestValue("action") != null) { this.action = this.getRequestValue("action"); } if (this.getRequestValue("range") != null) { this.range = this.getRequestValue("range"); } if (this.getRequestValue("item") != null) { this.item = this.getRequestValue("item"); } if ((this.getRequestValue("btn_store.x") != null) && (this.getRequestValue("btn_store.y") != null)) { this.action = "store"; } else if ((this.getRequestValue("btn_insert.x") != null) && (this.getRequestValue("btn_insert.y") != null)) { this.action = "insert"; } else if ((this.getRequestValue("btn_delete.x") != null) && (this.getRequestValue("btn_delete.y") != null)) { this.action = "delete"; } else if ((this.getRequestValue("btn_schema.x") != null) && (this.getRequestValue("btn_schema.y") != null)) { this.action = "schema"; } else if ((this.getRequestValue("btn_duplicate.x") != null) && (this.getRequestValue("btn_duplicate.y") != null)) { this.action = "duplicate"; this.range = "entries"; } else if ((this.getRequestValue("btn_cancel.x") != null) && (this.getRequestValue("btn_cancel.y") != null)) { this.action = "show"; if (this.range.equals("application")) { this.range = "applications"; } else if (this.range.equals("section")) { this.range = "sections"; } else { this.range = this.range.equals("list") ? "sections" : "entries"; } } else if ((this.getRequestValue("btn_query.x") != null) && (this.getRequestValue("btn_query.y") != null)) { this.action = "query"; this.range = "entries"; if (this.getRequestValue("query_select_range") != null && this.getRequestValue("query_select_range").equals("2")) { this.item = "replace"; } } else if ((this.getRequestValue("btn_export.x") != null) && (this.getRequestValue("btn_export.y") != null)) { this.action = "export"; this.range = "entries"; } else if ((this.getRequestValue("btn_import.x") != null) && (this.getRequestValue("btn_import.y") != null)) { this.action = "import"; this.range = "entries"; } else if ((this.getRequestValue("btn_clipboard_copy.x") != null) && (this.getRequestValue("btn_clipboard_copy.y") != null)) { if (this.getRequestValue("last_action") != null) { this.action = this.getRequestValue("last_action"); } else { this.action = "show"; } this.clipboardAction = "copy"; } else if ((this.getRequestValue("btn_clipboard_paste.x") != null) && (this.getRequestValue("btn_clipboard_paste.y") != null)) { if (this.getRequestValue("last_action") != null) { this.action = this.getRequestValue("last_action"); } else { this.action = "show"; } this.clipboardAction = "paste"; } else if ((this.getRequestValue("btn_import_file.x") != null) && (this.getRequestValue("btn_import_file.y") != null)) { this.action = ((this.getRequestValue("last_action") != null) && this.getRequestValue("last_action").equals("new")) ? "insert" : "store"; this.range = "entry"; this.item = "upload"; } if (this.getRequestValue("input_query") != null) { this.inputQuery = this.getRequestValue("input_query"); } if (this.getRequestValue("input_query_replace") != null) { this.replaceQuery = this.getRequestValue("input_query_replace"); } if (this.getRequestValue("input_export") != null) { this.inputExport = this.getRequestValue("input_export"); } if (this.getRequestValue("export_documentation") != null) { this.exportDocumentation = 1; } if (this.getRequestValue("input_import") != null) { this.inputImport = this.getRequestValue("input_import"); } } if (this.applicationName.equals("")) { this.applicationName = this.settings.application; } if (this.enableShowDevelopmentData) { this.showDevelopmentData(requestMultipart); } }