List of usage examples for org.apache.commons.fileupload FileItemStream getName
String getName();
From source file:com.serli.chell.framework.upload.FileUploadInfo.java
private static String getFilename(FileItemStream fis) { String filePath = fis.getName(); if (filePath != null && filePath.length() > 0) { return new File(filePath).getName(); }//from w ww . j av a 2 s . c om return null; }
From source file:DBMS.UpdateFileUpload.java
public static boolean processFile(String path, FileItemStream item, int id) { try {// w ww .j a va 2s .c o m String check = item.getName(); if (check.endsWith(".jpg") || check.endsWith(".JPG")) { String imstring = "images/" + Integer.toString(id); File f = new File(path + File.separator + imstring); if (!f.exists()) f.mkdir(); File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); String dbimage = imstring + "/a.jpg"; //dc.enterImage(dbimage); //im =dbimage; //System.out.println("Resizing!"); //Resize rz = new Resize(); //rz.resize(dbimage); BufferedImage originalImage = ImageIO.read(savedFile); int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizeImageJpg = resizeImage(originalImage, type); ImageIO.write(resizeImageJpg, "jpg", savedFile); File rFile = new File(f.getAbsolutePath() + "/a.jpg"); savedFile.renameTo(rFile); ProfileEditDB dc = new ProfileEditDB(); dc.enterImage(id, dbimage); System.out.println("Link Entered to Database!"); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Functions.FileUpload.java
public static boolean processFile(String path, FileItemStream item, String houseId, String owner) { if ("".equals(item.getName())) { return false; }//from ww w. j a v a 2 s .co m String nm = houseId + item.getName(); System.out.println("nm =====================" + nm); try { File f = new File(path + File.separator + "images/"); if (!f.exists()) {//den uparxei kan o fakelos opote den einai sthn database tpt! System.out.println("Mphke sthn if den exists"); f.mkdir(); File savedFile = new File(f.getAbsoluteFile() + File.separator + nm); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); database_common_functions.insertIntoBaseImage(houseId, nm); return true; } else { System.out.println("Mphke sthn if exists"); if (database_common_functions.isHouseImageInDatabase(houseId, nm) == 1) { //overwrites current image with name nm. System.out.println("Mphke na kanei overwrite t arxeio"); FileOutputStream fos = new FileOutputStream(f.getAbsoluteFile() + File.separator + nm); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); return true; } else { FileOutputStream fos = new FileOutputStream(f.getAbsoluteFile() + File.separator + nm); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); database_common_functions.insertIntoBaseImage(houseId, nm); return true; } } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.chinarewards.gwt.license.util.FileUploadServlet.java
private static String getOutputFileName(FileItemStream item) { String itemName = item.getName(); itemName = itemName.substring(itemName.lastIndexOf("."), itemName.length()); String fileName = DateUtil.getDateString("yyyyMMddHHmmss"); fileName += new Random().nextInt(10000); fileName += itemName;// w ww . j a v a2 s . c om return fileName; }
From source file:com.elit2.app.model.FileUpload.java
public static boolean proccessFile(String path, FileItemStream item) { try {/*from ww w . j a v a 2s . c o m*/ File f = new File(path + File.separator + "images"); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read()) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception ex) { ex.printStackTrace(); } return false; }
From source file:in.co.sneh.model.CargaExcelRuralModel.java
public static boolean processFile(String path, FileItemStream item) { try {/*w w w . j a va 2s .co m*/ File f = new File(path + File.separator + "exceles" + File.separator); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception e) { System.out.println(e.getMessage()); } return false; }
From source file:helpers.FileUpload.java
public static boolean processFile(String path, FileItemStream item) { try {/* www . ja v a 2 s . co m*/ File f = new File(path + File.separator + "assets" + File.separator + "uploads"); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception e) { System.out.println("FileUpload 35: " + e.getMessage()); } return false; }
From source file:elw.web.ControllerElw.java
protected static String extractNameFromPath(FileItemStream item) { final String name = item.getName(); if (name == null) { return null; }/*from w w w . ja v a2 s .com*/ final int lastSlash = Math.max(name.lastIndexOf("\\"), name.lastIndexOf("/")); final String fName = lastSlash >= 0 ? name.substring(lastSlash + 1) : name; return fName; }
From source file:uploadProcess.java
public static boolean encrypt(String path, FileItemStream item, String patientID) { try {/*from ww w. ja v a2 s. c om*/ File mainFolder = new File(path + File.separator + "Encrypt"); if (!mainFolder.exists()) { mainFolder.mkdir(); } File patientFolder = new File(mainFolder + File.separator + patientID); if (!patientFolder.exists()) { patientFolder.mkdir(); } String ukey = GetKey.getPatientKey(patientID); InputStream fis = item.openStream(); FileOutputStream fos = new FileOutputStream( patientFolder.getAbsolutePath() + File.separator + item.getName()); byte[] k = ukey.getBytes(); SecretKeySpec key = new SecretKeySpec(k, "AES"); System.out.println(key); Cipher enc = Cipher.getInstance("AES"); enc.init(Cipher.ENCRYPT_MODE, key); CipherOutputStream cos = new CipherOutputStream(fos, enc); byte[] buf = new byte[1024]; int read; while ((read = fis.read(buf)) != -1) { cos.write(buf, 0, read); } fis.close(); fos.flush(); cos.close(); //Upload File to cloud DropboxUpload upload = new DropboxUpload(); upload.uploadFile(patientFolder, item.getName(), StoragePath.getDropboxDir() + patientID); DeleteDirectory.delete(patientFolder); return true; } catch (Exception e) { System.out.println("Error: " + e); } return false; }
From source file:com.twosigma.beaker.core.module.elfinder.impl.commands.UploadCommand.java
@Override @SuppressWarnings("unchecked") public void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json) throws Exception { List<FileItemStream> listFiles = (List<FileItemStream>) request .getAttribute(FileItemStream.class.getName()); List<FsItemEx> added = new ArrayList<FsItemEx>(); String target = request.getParameter("target"); FsItemEx dir = super.findItem(fsService, target); FsItemFilter filter = FsItemFilterUtils.createFilterFromRequest(request); for (FileItemStream fis : listFiles) { java.nio.file.Path p = java.nio.file.Paths.get(fis.getName()); FsItemEx newFile = new FsItemEx(dir, p.getFileName().toString()); newFile.createFile();//w w w . ja va 2s.c o m InputStream is = fis.openStream(); newFile.writeStream(is); if (filter.accepts(newFile)) added.add(newFile); } json.put("added", files2JsonArray(request, added)); }