diff options
author | Vitaly Takmazov | 2016-01-14 06:31:38 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-01-14 06:31:38 +0300 |
commit | 7e93e142b6dd75c22c057962447eec014c4e15b4 (patch) | |
tree | e21fa5dc42ecf19ec0084956393340ef668fcb79 | |
parent | be5c5b0ec0574ff13f4ff2ecd7fb10490bfecbe2 (diff) |
fix multipart parsing
-rw-r--r-- | src/main/java/com/juick/http/www/Utils.java | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/main/java/com/juick/http/www/Utils.java b/src/main/java/com/juick/http/www/Utils.java index e6fcad72..21577a40 100644 --- a/src/main/java/com/juick/http/www/Utils.java +++ b/src/main/java/com/juick/http/www/Utils.java @@ -60,15 +60,17 @@ public class Utils { Part filePart = request.getPart("attach"); if (filePart != null) { String partname = Utils.getPartFilename(filePart); - String attachmentType = partname.substring(partname.length() - 3).toLowerCase(); - if (attachmentType.equals("jpg") || attachmentType.equals("peg") || attachmentType.equals("png")) { - if (attachmentType.equals("peg")) { - attachmentType = "jpg"; + if (partname != null && partname.length() > 0) { + String attachmentType = partname.substring(partname.length() - 3).toLowerCase(); + if (attachmentType.equals("jpg") || attachmentType.equals("peg") || attachmentType.equals("png")) { + if (attachmentType.equals("peg")) { + attachmentType = "jpg"; + } + attachmentFName = UUID.randomUUID().toString() + "." + attachmentType; + filePart.write("/var/www/juick.com/i/tmp/" + attachmentFName); + } else { + throw new Exception("Wrong file type"); } - attachmentFName = UUID.randomUUID().toString() + "." + attachmentType; - filePart.write("/var/www/juick.com/i/tmp/" + attachmentFName); - } else { - throw new Exception("Wrong file type"); } } |