diff options
author | Vitaly Takmazov | 2016-09-05 01:35:19 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-09-05 01:46:49 +0300 |
commit | cfd873f5c5e52eb89b7985555afdb1a180e71620 (patch) | |
tree | 79a8dead3e255215c929fa06172adf42ea8a7254 /juick-www/src/main/java/com/juick/www/Utils.java | |
parent | 7523a0a69ebe45afc98394f52ce14ac530ca9b18 (diff) |
avatar uploading
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/Utils.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/Utils.java | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/juick-www/src/main/java/com/juick/www/Utils.java b/juick-www/src/main/java/com/juick/www/Utils.java index ee2fa212..4be659cb 100644 --- a/juick-www/src/main/java/com/juick/www/Utils.java +++ b/juick-www/src/main/java/com/juick/www/Utils.java @@ -21,6 +21,7 @@ import com.juick.User; import com.mitchellbosecke.pebble.PebbleEngine; import org.springframework.jdbc.core.JdbcTemplate; +import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -28,6 +29,7 @@ import javax.servlet.http.Part; import java.io.*; import java.net.URL; import java.net.URLConnection; +import java.nio.file.Paths; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -42,6 +44,7 @@ public class Utils { private static final Logger logger = Logger.getLogger(Utils.class.getName()); private static final PebbleEngine engine = new PebbleEngine.Builder().build(); + private static String tmpDir = "/var/www/juick.com/i/tmp/"; public static String getCookie(HttpServletRequest request, String name) { Cookie cookies[] = request.getCookies(); @@ -55,10 +58,10 @@ public class Utils { return null; } - public static String receiveMultiPartFile(HttpServletRequest request, String name) throws Exception { + public static String receiveMultiPartFile(HttpServletRequest request, String name) throws IOException, ServletException { String attachmentFName = null; - Part filePart = request.getPart("attach"); + Part filePart = request.getPart(name); if (filePart != null) { String partname = Utils.getPartFilename(filePart); if (partname != null && partname.length() > 0) { @@ -68,9 +71,9 @@ public class Utils { attachmentType = "jpg"; } attachmentFName = UUID.randomUUID().toString() + "." + attachmentType; - filePart.write("/var/www/juick.com/i/tmp/" + attachmentFName); + filePart.write(Paths.get(getTmpDir(), attachmentFName).toString()); } else { - throw new Exception("Wrong file type"); + throw new IOException("Wrong file type"); } } } @@ -299,4 +302,12 @@ public class Utils { public static PebbleEngine getEngine() { return engine; } + + public static String getTmpDir() { + return tmpDir; + } + + public static void setTmpDir(String tmpDir) { + Utils.tmpDir = tmpDir; + } } |