From cc150a2cc6fa01d871508da14ac62f8b39e6ab2d Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Fri, 20 Oct 2017 09:41:34 +0800 Subject: [PATCH] =?UTF-8?q?@RestUploadFile=E6=A0=87=E8=AE=B0=E7=9A=84File?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=8F=AF=E4=BB=A5=E8=8E=B7=E5=8F=96=E5=88=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=8A=E4=BC=A0=E7=9A=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/net/http/MultiContext.java | 24 ++++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/org/redkale/net/http/MultiContext.java b/src/org/redkale/net/http/MultiContext.java index 77cb31f32..343f5a6da 100644 --- a/src/org/redkale/net/http/MultiContext.java +++ b/src/org/redkale/net/http/MultiContext.java @@ -133,17 +133,13 @@ public final class MultiContext { has = true; if (filenameReg != null && !filenameReg.isEmpty() && !part.getFilename().matches(filenameReg)) continue; if (contentTypeReg != null && !contentTypeReg.isEmpty() && !part.getContentType().matches(contentTypeReg)) continue; - String name = part.getFilename(); - int pos = name.lastIndexOf('.'); - if (pos > 0) { - int pos2 = name.lastIndexOf('.', pos - 1); - if (pos2 >= 0) pos = pos2; - } - File file = new File(home, "tmp/redkale_" + System.nanoTime() + (pos > 0 ? name.substring(pos) : name)); - file.getParentFile().mkdirs(); + File file = new File(home, "tmp/redkale_" + System.nanoTime() + "/" + part.getFilename()); + File parent = file.getParentFile(); + parent.mkdirs(); boolean rs = part.save(max < 1 ? Long.MAX_VALUE : max, file); if (!rs) { file.delete(); + parent.delete(); } else { tmpfile = file; } @@ -169,17 +165,13 @@ public final class MultiContext { for (MultiPart part : parts()) { if (filenameReg != null && !filenameReg.isEmpty() && !part.getFilename().matches(filenameReg)) continue; if (contentTypeReg != null && !contentTypeReg.isEmpty() && !part.getContentType().matches(contentTypeReg)) continue; - String name = part.getFilename(); - int pos = name.lastIndexOf('.'); - if (pos > 0) { - int pos2 = name.lastIndexOf('.', pos - 1); - if (pos2 >= 0) pos = pos2; - } - File file = new File(home, "tmp/redkale_" + System.nanoTime() + (pos > 0 ? name.substring(pos) : name)); - file.getParentFile().mkdirs(); + File file = new File(home, "tmp/redkale_" + System.nanoTime() + "/" + part.getFilename()); + File parent = file.getParentFile(); + parent.mkdirs(); boolean rs = part.save(max < 1 ? Long.MAX_VALUE : max, file); if (!rs) { file.delete(); + parent.delete(); continue; } if (files == null) files = new ArrayList<>();