aboutsummaryrefslogtreecommitdiff
path: root/juick-api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-08 16:14:34 +0300
committerGravatar Vitaly Takmazov2016-12-08 16:59:04 +0300
commit34f9a7dad5535870486edb304ee8043381f7cbdd (patch)
tree1c5d903f92d7383d2a6700947e64d976a68c0cd1 /juick-api
parent7e954500ee1b68ad07e2b0bda4eb549ee99167b4 (diff)
juick-api: fix upload
Diffstat (limited to 'juick-api')
-rw-r--r--juick-api/build.gradle1
-rw-r--r--juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java8
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Post.java8
-rw-r--r--juick-api/src/main/java/com/juick/api/util/HttpUtils.java2
4 files changed, 14 insertions, 5 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle
index c160da96..cbce7f43 100644
--- a/juick-api/build.gradle
+++ b/juick-api/build.gradle
@@ -13,6 +13,7 @@ dependencies {
compile project(':juick-server')
compile "org.springframework:spring-webmvc:${rootProject.springFrameworkVersion}"
+ runtime "commons-fileupload:commons-fileupload:1.3.2"
compile 'com.github.pengrad:java-telegram-bot-api:2.3.0'
compile 'com.neovisionaries:nv-websocket-client:1.30'
diff --git a/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java b/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java
index 549de8bc..5a953c1f 100644
--- a/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java
+++ b/juick-api/src/main/java/com/juick/api/configuration/ApiMvcConfiguration.java
@@ -2,11 +2,13 @@ package com.juick.api.configuration;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@@ -38,4 +40,10 @@ public class ApiMvcConfiguration extends WebMvcConfigurationSupport {
converters.add(converter);
super.configureMessageConverters(converters);
}
+ @Bean
+ public CommonsMultipartResolver multipartResolver() {
+ CommonsMultipartResolver resolver = new CommonsMultipartResolver();
+ resolver.setMaxUploadSize(10000000);
+ return resolver;
+ }
}
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 9749d700..40c6207e 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
@@ -111,7 +111,7 @@ public class Post {
}
}
- String attachmentType = attachmentFName != null ? attachmentFName.substring(attachmentFName.length() - 3) : null;
+ String attachmentType = StringUtils.isNotEmpty(attachmentFName) ? attachmentFName.substring(attachmentFName.length() - 3) : null;
int mid = messagesService.createMessage(vuid, body, attachmentType, tagsList);
subscriptionService.subscribeMessage(mid, vuid);
com.juick.Message jmsg = messagesService.getMessage(mid);
@@ -124,7 +124,7 @@ public class Post {
xmsg.addExtension(jmsg);
xmsg.addExtension(new Nickname("@" + jmsg.getUser().getName()));
- if (attachmentFName != null) {
+ if (StringUtils.isNotEmpty(attachmentFName)) {
String fname = mid + "." + attachmentType;
String attachmentURL = "http://i.juick.com/photos-1024/" + fname;
@@ -227,7 +227,7 @@ public class Post {
}
}
- String attachmentType = attachmentFName != null ? attachmentFName.substring(attachmentFName.length() - 3) : null;
+ String attachmentType = StringUtils.isNotEmpty(attachmentFName) ? attachmentFName.substring(attachmentFName.length() - 3) : null;
int ridnew = messagesService.createReply(mid, rid, vuid, body, attachmentType);
subscriptionService.subscribeMessage(mid, vuid);
@@ -247,7 +247,7 @@ public class Post {
xmsg.addExtension(new Nickname("@" + jmsg.getUser().getName()));
- if (attachmentFName != null) {
+ if (StringUtils.isNotEmpty(attachmentFName)) {
String fname = mid + "-" + ridnew + "." + attachmentType;
String attachmentURL = "http://i.juick.com/photos-1024/" + fname;
diff --git a/juick-api/src/main/java/com/juick/api/util/HttpUtils.java b/juick-api/src/main/java/com/juick/api/util/HttpUtils.java
index 2f8ca7c5..93fb7874 100644
--- a/juick-api/src/main/java/com/juick/api/util/HttpUtils.java
+++ b/juick-api/src/main/java/com/juick/api/util/HttpUtils.java
@@ -38,7 +38,7 @@ public class HttpUtils {
private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
public static String receiveMultiPartFile(MultipartFile attach, String tmpDir) {
- if (!attach.isEmpty()) {
+ if (attach !=null && !attach.isEmpty()) {
String partname = attach.getOriginalFilename();
if (partname != null && partname.length() > 0) {
String attachmentType = partname.substring(partname.length() - 3).toLowerCase();