From a5f045a3780ef8530afa7493cf090771b8fdcfe1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 3 Apr 2018 17:55:46 +0300 Subject: refactoring: all messages are processed with XMPPConnection --- .../src/main/java/com/juick/server/util/HttpUtils.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'juick-common') diff --git a/juick-common/src/main/java/com/juick/server/util/HttpUtils.java b/juick-common/src/main/java/com/juick/server/util/HttpUtils.java index 35f594f3..f86e52c5 100644 --- a/juick-common/src/main/java/com/juick/server/util/HttpUtils.java +++ b/juick-common/src/main/java/com/juick/server/util/HttpUtils.java @@ -24,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; @@ -37,7 +38,7 @@ import java.util.UUID; public class HttpUtils { private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class); - public static String receiveMultiPartFile(MultipartFile attach, String tmpDir) { + public static URI receiveMultiPartFile(MultipartFile attach, String tmpDir) { if (attach !=null && !attach.isEmpty()) { String partname = attach.getOriginalFilename(); if (partname != null && partname.length() > 0) { @@ -50,16 +51,16 @@ public class HttpUtils { try { Files.write(Paths.get(tmpDir, attachmentFName), attach.getBytes()); - return attachmentFName; + return URI.create(String.format("juick://%s", attachmentFName)); } catch (IOException e) { logger.warn("file receive error", e); } } } } - return StringUtils.EMPTY; + return URI.create(""); } - public static String downloadImage(URL url, String tmpDir) throws Exception { + public static URI downloadImage(URL url, String tmpDir) throws Exception { URLConnection urlConn; try { urlConn = url.openConnection(); @@ -86,7 +87,7 @@ public class HttpUtils { String attachmentFName = DigestUtils.md5Hex(UUID.randomUUID().toString()) + "." + attachmentType; Files.copy(is, Paths.get(tmpDir, attachmentFName)); - return attachmentFName; + return URI.create(String.format("juick://%s", attachmentFName)); } catch (Exception e) { logger.error(String.format("Failed download image by url: %s", url.toString()), e); throw e; -- cgit v1.2.3