From c6e5f4092997365a36b2acd8d2c445714e36c6a1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 6 Nov 2015 14:33:27 +0300 Subject: try https downloads --- src/main/java/com/juick/http/www/NewMessage.java | 10 ++++++---- src/main/java/com/juick/http/www/Utils.java | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/juick/http/www/NewMessage.java b/src/main/java/com/juick/http/www/NewMessage.java index e2fe9629..d6ef22ee 100644 --- a/src/main/java/com/juick/http/www/NewMessage.java +++ b/src/main/java/com/juick/http/www/NewMessage.java @@ -33,6 +33,7 @@ import com.juick.xmpp.extensions.XOOB; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.net.URL; import java.net.URLEncoder; import java.sql.Connection; import java.util.ArrayList; @@ -169,9 +170,10 @@ public class NewMessage { } String paramImg = request.getParameter("img"); - if (attachmentFName == null && paramImg != null && paramImg.length() > 12 && paramImg.startsWith("http://") && !paramImg.equals("http://")) { + if (attachmentFName == null && paramImg != null) { try { - attachmentFName = Utils.downloadImage(paramImg); + URL imgUrl = new URL(paramImg); + attachmentFName = Utils.downloadImage(imgUrl); } catch (Exception e) { System.out.println("DOWNLOAD ERROR: " + e.toString()); response.sendError(500); @@ -326,9 +328,9 @@ public class NewMessage { } String paramImg = request.getParameter("img"); - if (attachmentFName == null && paramImg != null && paramImg.length() > 12 && paramImg.startsWith("http://") && !paramImg.equals("http://")) { + if (attachmentFName == null && paramImg != null) { try { - attachmentFName = Utils.downloadImage(paramImg); + attachmentFName = Utils.downloadImage(new URL(paramImg)); } catch (Exception e) { System.out.println("DOWNLOAD ERROR: " + e.toString()); response.sendError(500); diff --git a/src/main/java/com/juick/http/www/Utils.java b/src/main/java/com/juick/http/www/Utils.java index afaf131e..e6fcad72 100644 --- a/src/main/java/com/juick/http/www/Utils.java +++ b/src/main/java/com/juick/http/www/Utils.java @@ -193,14 +193,14 @@ public class Utils { } } - public static String downloadImage(String url) throws Exception { + public static String downloadImage(URL url) throws Exception { String attachmentFName = null; Exception ex = null; InputStream is = null; FileOutputStream fos = null; try { - URLConnection urlConn = new URL(url).openConnection(); + URLConnection urlConn = url.openConnection(); is = urlConn.getInputStream(); String mime = urlConn.getContentType(); -- cgit v1.2.3