aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-14 06:31:38 +0300
committerGravatar Vitaly Takmazov2016-01-14 06:31:38 +0300
commit7e93e142b6dd75c22c057962447eec014c4e15b4 (patch)
treee21fa5dc42ecf19ec0084956393340ef668fcb79 /src/main/java
parentbe5c5b0ec0574ff13f4ff2ecd7fb10490bfecbe2 (diff)
fix multipart parsing
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/juick/http/www/Utils.java18
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");
}
}