Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String uploadFile(UploadedFile doc) {
- UploadedFile myDoc = doc;
- String path = null;
- if (myDoc == null) {
- } else {
- InputStream inputStream = null;
- try {
- path =
- new File("..\\images\\new_layout\\vehicle_images").getCanonicalPath() + File.separator + new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()) +
- "_" + myDoc.getFilename();
- //for LOCAL testing
- // path =
- // "D:\\TRAXXEO_APPLICATION\\ViewController\\public_html\\images\\new_layout\\vehicle_images\\" +
- // new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new java.util.Date()) + "_" + myDoc.getFilename();
- System.out.println(path + " PATH + FILENAME ");
- FileOutputStream out = new FileOutputStream(path);
- inputStream = myDoc.getInputStream();
- byte[] buffer = new byte[8192];
- int bytesRead = 0;
- while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
- out.write(buffer, 0, bytesRead);
- }
- out.flush();
- out.close();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- } finally {
- try {
- inputStream.close();
- } catch (IOException ioex) {
- log.error(ioex.getMessage(), ioex);
- }
- }
- }
- return path;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement