diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index 47b7552..e6406c4 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -245,16 +245,18 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar //generate the random dir File theRandomDir = new File(UPLOAD_LOCATION_LOCAL + File.separator + UUID.randomUUID().toString()); theRandomDir.mkdir(); + theRandomDir.deleteOnExit(); _log.debug("Created temp upload directory in: " + theRandomDir); // generate a random file name and create it under the randomDir File file = new File(theRandomDir, UUID.randomUUID().toString().substring(0, 10)); + file.deleteOnExit(); //Get the inputstream and copy there URL url = new URL(urlThumbnail); Streams.copy(url.openStream(), new FileOutputStream(file), true); _log.debug("File is at " + file.getAbsolutePath()); - + return file; }else return null; @@ -289,12 +291,6 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar break; default: break; } - - //delete file and folder - File parentDir = localFile.getParentFile(); - localFile.delete(); - parentDir.delete(); - return thumbnailUrlFTP; } catch (IOException e) { _log.error("Error while saving thumbnail on ftp", e); @@ -302,7 +298,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } }else _log.warn("the file at url " + urlThumbnail + " doesn't exist"); - + return null; }