Advertisement
psi_mmobile

Untitled

Dec 19th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1.     private String uploadFile(UploadedFile doc) {
  2.         UploadedFile myDoc = doc;
  3.         String path = null;
  4.         if (myDoc == null) {
  5.  
  6.         } else {
  7.             InputStream inputStream = null;
  8.             try {
  9.  
  10.                 path =
  11.     new File("..\\images\\new_layout\\vehicle_images").getCanonicalPath() + File.separator + new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()) +
  12.     "_" + myDoc.getFilename();
  13.      
  14.                 //for LOCAL testing
  15. //                path =
  16. //                "D:\\TRAXXEO_APPLICATION\\ViewController\\public_html\\images\\new_layout\\vehicle_images\\" +
  17. //                 new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new java.util.Date()) + "_" + myDoc.getFilename();
  18.                 System.out.println(path + " PATH + FILENAME ");
  19.                 FileOutputStream out = new FileOutputStream(path);
  20.                 inputStream = myDoc.getInputStream();
  21.                 byte[] buffer = new byte[8192];
  22.                 int bytesRead = 0;
  23.                 while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
  24.                     out.write(buffer, 0, bytesRead);
  25.                 }
  26.                 out.flush();
  27.                 out.close();
  28.             } catch (Exception ex) {
  29.                 log.error(ex.getMessage(), ex);
  30.             } finally {
  31.                 try {
  32.                     inputStream.close();
  33.                 } catch (IOException ioex) {
  34.                     log.error(ioex.getMessage(), ioex);
  35.                 }
  36.             }
  37.         }
  38.         return path;
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement