From 7e93e142b6dd75c22c057962447eec014c4e15b4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 14 Jan 2016 06:31:38 +0300 Subject: fix multipart parsing --- src/main/java/com/juick/http/www/Utils.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/juick') 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"); } } -- cgit v1.2.3