aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Post.java10
-rw-r--r--juick-server/src/main/java/com/juick/server/util/HttpUtils.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java4
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java2
4 files changed, 9 insertions, 11 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-api/src/main/java/com/juick/api/controllers/Post.java
index 322587fb..0173cf04 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Post.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Post.java
@@ -70,13 +70,12 @@ public class Post {
}
body = body.replace("\r", StringUtils.EMPTY);
- String attachmentFName = HttpUtils.receiveMultiPartFile(attach, env.getProperty("upload_tmp_dir",
- "/var/www/juick.com/i/tmp/"));
+ String attachmentFName = HttpUtils.receiveMultiPartFile(attach, apiServer.tmpDir);
if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl);
+ attachmentFName = HttpUtils.downloadImage(imgUrl, apiServer.tmpDir);
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
@@ -139,12 +138,11 @@ public class Post {
throw new HttpForbiddenException();
}
- String attachmentFName = HttpUtils.receiveMultiPartFile(attach, env.getProperty("upload_tmp_dir",
- "/var/www/juick.com/i/tmp/"));
+ String attachmentFName = HttpUtils.receiveMultiPartFile(attach, apiServer.tmpDir);
if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
try {
- attachmentFName = HttpUtils.downloadImage(new URL(img));
+ attachmentFName = HttpUtils.downloadImage(new URL(img), apiServer.tmpDir);
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
diff --git a/juick-server/src/main/java/com/juick/server/util/HttpUtils.java b/juick-server/src/main/java/com/juick/server/util/HttpUtils.java
index e54bef87..c305093c 100644
--- a/juick-server/src/main/java/com/juick/server/util/HttpUtils.java
+++ b/juick-server/src/main/java/com/juick/server/util/HttpUtils.java
@@ -61,7 +61,7 @@ public class HttpUtils {
}
return StringUtils.EMPTY;
}
- public static String downloadImage(URL url) throws Exception {
+ public static String downloadImage(URL url, String tmpDir) throws Exception {
String attachmentFName = null;
Exception ex = null;
@@ -82,7 +82,7 @@ public class HttpUtils {
}
attachmentFName = UUID.randomUUID().toString() + "." + attachmentType;
- fos = new FileOutputStream("/var/www/juick.com/i/tmp/" + attachmentFName);
+ fos = new FileOutputStream(Paths.get(tmpDir, attachmentFName).toString());
byte[] buffer = new byte[10240];
int len;
while ((len = is.read(buffer)) > 0) {
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
index 7875f52b..1931b1d9 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
@@ -203,7 +203,7 @@ public class NewMessage {
if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl);
+ attachmentFName = HttpUtils.downloadImage(imgUrl, webApp.getTmpDir());
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
@@ -356,7 +356,7 @@ public class NewMessage {
if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl);
+ attachmentFName = HttpUtils.downloadImage(imgUrl, webApp.getTmpDir());
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();
diff --git a/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java b/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java
index 330f277c..45fff7ce 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/XMPPPost.java
@@ -52,7 +52,7 @@ public class XMPPPost {
if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) {
try {
URL imgUrl = new URL(img);
- attachmentFName = HttpUtils.downloadImage(imgUrl);
+ attachmentFName = HttpUtils.downloadImage(imgUrl, webApp.getTmpDir());
} catch (Exception e) {
logger.error("DOWNLOAD ERROR", e);
throw new HttpBadRequestException();