Commit 2f926f92 by fukai

优化下载

parent 679dbc65
......@@ -2,20 +2,14 @@ package org.sss.presentation.noui.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import log.Log;
import log.LogFactory;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils;
import org.springframework.web.multipart.MultipartFile;
import org.sss.common.model.EventType;
import org.sss.common.model.IBaseObject;
import org.sss.common.model.IDatafield;
......@@ -37,7 +31,8 @@ import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.RedisUtil;
import org.sss.presentation.noui.util.StringUtil;
import com.google.gson.Gson;
import log.Log;
import log.LogFactory;
public class AbstractCommonController {
protected static final Log log = LogFactory.getLog(AbstractCommonController.class);
......@@ -49,38 +44,37 @@ public class AbstractCommonController {
protected static String ON_STREAM_DOWNLOAD = "ON_STREAM_DOWNLOAD";
@SuppressWarnings("unchecked")
public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, HttpServletRequest request, HttpServletResponse response) {
public Object event(String mappingUrl, String eventType,MultipartFile file, Map<String, Object> dataMap, HttpServletRequest request, HttpServletResponse response) {
NoUiContext context = null;
Result ret = null;
boolean isMultipart = false;
FileItem lastFileItem = null;
try {
isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
// Parse the request
List<FileItem> items = upload.parseRequest(request);
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext()) {
FileItem item = iter.next();
// 普通表单域
if (item.isFormField()) {
String itemName = item.getFieldName();
String itemValue = item.getString();
log.info("文件表单 key:" + itemName + ",Value:" + itemValue);
// 给dataMap赋值
Map<String, ?> itemMap = new Gson().fromJson(itemValue, Map.class);
dataMap.put(itemName, itemMap);
} else { // 文件域
lastFileItem = item;
}
}
} else {
log.info("普通表单key-Value:" + dataMap);
}
// isMultipart = ServletFileUpload.isMultipartContent(request);
// if (isMultipart) {
//
// ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
// // Parse the request
// List<FileItem> items = upload.parseRequest(request);
// Iterator<FileItem> iter = items.iterator();
//
// while (iter.hasNext()) {
// FileItem item = iter.next();
// // 普通表单域
// if (item.isFormField()) {
// String itemName = item.getFieldName();
// String itemValue = item.getString();
// log.info("文件表单 key:" + itemName + ",Value:" + itemValue);
// // 给dataMap赋值
// Map<String, ?> itemMap = new Gson().fromJson(itemValue, Map.class);
// dataMap.put(itemName, itemMap);
// } else { // 文件域
// lastFileItem = item;
// }
// }
// } else {
// log.info("普通表单key-Value:" + dataMap);
// }
NoUiRequest noUiRequest = new NoUiRequest(request, mappingUrl, dataMap);
context = NoUiContextManager.createNoUiContext(noUiRequest);
Alias alias = new Alias(mappingUrl);
......@@ -117,14 +111,14 @@ public class AbstractCommonController {
((IDatafield<?>) currentDataField).invokeCheckRules(context);
}
}
} else if (eventType.equals(ON_STREAM_UPLOAD) && lastFileItem != null) {
} else if (eventType.equals(ON_STREAM_UPLOAD) && file != null) {
@SuppressWarnings("rawtypes")
IDatafield dataField = (IDatafield) baseObject(context, noUiRequest, alias);
IStream stream = (IStream) dataField.getValue();
stream.setName(lastFileItem.getName());
stream.setType(lastFileItem.getContentType());
IOUtils.copy(lastFileItem.getInputStream(), stream.getOutputStream(), 1024);
// dataField.setValue(stream);
stream.setName(file.getName());
stream.setType(file.getContentType());
log.info("文件表单 key:" + file.getName() + ",size:" + file.getSize());
IOUtils.copy(file.getInputStream(), stream.getOutputStream(), 1024);
dataField.invokeEventRules(context, EventType.ON_STREAM_UPLOAD, null);
} else if (eventType.equals(ON_STREAM_DOWNLOAD)) {
@SuppressWarnings("rawtypes")
......
......@@ -26,6 +26,10 @@
<bean class="org.sss.presentation.noui.jwt.TokenInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="200000" />
<property name="maxInMemorySize" value="200000" />
</bean>
<!-- 配置自动扫描的包 -->
<context:component-scan base-package="org.sss.presentation.noui.controller"></context:component-scan>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment