private static final String UPLOADDIR = "uploadir";
@ResponseBody
@RequestMapping(value = "uploadServer")
public String sendFileToServer(HttpServletResponse response, HttpServletRequest request) throws Exception
{
log.debug(Constant.ENTER_FUNCTION);
// 解析多重请求
MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = mRequest.getFileMap();
String fileName = null;
String downloadPath = null;// 返回路径
String originalPath = null;// 原路径
String breviaryPath = null;// 缩略图路径
String oldName = null;// 原图名
String breviaryName = null;// 缩略图名
String type = request.getParameter("type").trim();
String remark = request.getParameter("remark");
String bigType = request.getParameter("bigType");
String script = null;
if (StringUtils.isEmpty(type) || StringUtils.isEmpty(remark) || StringUtils.isEmpty(bigType))
{
log.warn("remark and type is null" + type + "" + remark + "" + bigType);
script = buildReturnScript(0);
return script;
}
int i = 0;
for (Iterator<Map.Entry<String, MultipartFile>> it = fileMap.entrySet().iterator(); it.hasNext();)
{
++i;
Map.Entry<String, MultipartFile> entry = it.next();
MultipartFile mFile = entry.getValue();
fileName = mFile.getOriginalFilename();
if (StringUtils.isEmpty(fileName))
{
log.warn("fileName is not null");
script = buildReturnScript(0);
}
else
{
// 自己服务器tomcat下路径
String uploadDir = request.getSession().getServletContext().getRealPath("/")
+ UploadDownloadController.UPLOADDIR;
File file = new File(uploadDir);
if (!file.exists())
{
file.mkdir();
}
String filePath = uploadDir + fileName;
file = new File(filePath);
// 转存到本地服务器
mFile.transferTo(file);
String retString = BBKUploadService.updateLoad(mFile, request, SN, Constant.FLAG); // 这是上传到云存储的方法,返回图片路径
// 获取token失败
if (retString.equals(Constant.FLAG))
{
return buildReturnScript(0);
}
else if (retString.equals(UPLOAD_FAIL))
{
return buildReturnScript(0);
}
downloadPath = retString.substring(retString.indexOf("=") + 1);
if (i == 1)
{
originalPath = downloadPath;
oldName = fileName;
}
else
{
breviaryPath = downloadPath;
breviaryName = fileName;
}
log.debug(Constant.EXIT_FUNCTION);
log.debug("downloadPath = " + downloadPath);
// 上传成功后把临时文件删除
// CommonUtil.deleteFile(filePath);
}
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("oldPath", originalPath);
params.put("breviaryPath", breviaryPath);
params.put("type", type);
params.put("bigType", bigType);
params.put("breviaryName", breviaryName);
params.put("oldName", oldName);
params.put("remark", remark);
// 上传成功后把路径保存到数据库
int result = uploadDownloadService.insert(params);
if (result == 1)
{
script = buildReturnScript(result);
}
else
{
script = buildReturnScript(0);
}
return script;
}
@ResponseBody
@RequestMapping(value = "uploadServer")
public String sendFileToServer(HttpServletResponse response, HttpServletRequest request) throws Exception
{
log.debug(Constant.ENTER_FUNCTION);
// 解析多重请求
MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = mRequest.getFileMap();
String fileName = null;
String downloadPath = null;// 返回路径
String originalPath = null;// 原路径
String breviaryPath = null;// 缩略图路径
String oldName = null;// 原图名
String breviaryName = null;// 缩略图名
String type = request.getParameter("type").trim();
String remark = request.getParameter("remark");
String bigType = request.getParameter("bigType");
String script = null;
if (StringUtils.isEmpty(type) || StringUtils.isEmpty(remark) || StringUtils.isEmpty(bigType))
{
log.warn("remark and type is null" + type + "" + remark + "" + bigType);
script = buildReturnScript(0);
return script;
}
int i = 0;
for (Iterator<Map.Entry<String, MultipartFile>> it = fileMap.entrySet().iterator(); it.hasNext();)
{
++i;
Map.Entry<String, MultipartFile> entry = it.next();
MultipartFile mFile = entry.getValue();
fileName = mFile.getOriginalFilename();
if (StringUtils.isEmpty(fileName))
{
log.warn("fileName is not null");
script = buildReturnScript(0);
}
else
{
// 自己服务器tomcat下路径
String uploadDir = request.getSession().getServletContext().getRealPath("/")
+ UploadDownloadController.UPLOADDIR;
File file = new File(uploadDir);
if (!file.exists())
{
file.mkdir();
}
String filePath = uploadDir + fileName;
file = new File(filePath);
// 转存到本地服务器
mFile.transferTo(file);
String retString = BBKUploadService.updateLoad(mFile, request, SN, Constant.FLAG); // 这是上传到云存储的方法,返回图片路径
// 获取token失败
if (retString.equals(Constant.FLAG))
{
return buildReturnScript(0);
}
else if (retString.equals(UPLOAD_FAIL))
{
return buildReturnScript(0);
}
downloadPath = retString.substring(retString.indexOf("=") + 1);
if (i == 1)
{
originalPath = downloadPath;
oldName = fileName;
}
else
{
breviaryPath = downloadPath;
breviaryName = fileName;
}
log.debug(Constant.EXIT_FUNCTION);
log.debug("downloadPath = " + downloadPath);
// 上传成功后把临时文件删除
// CommonUtil.deleteFile(filePath);
}
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("oldPath", originalPath);
params.put("breviaryPath", breviaryPath);
params.put("type", type);
params.put("bigType", bigType);
params.put("breviaryName", breviaryName);
params.put("oldName", oldName);
params.put("remark", remark);
// 上传成功后把路径保存到数据库
int result = uploadDownloadService.insert(params);
if (result == 1)
{
script = buildReturnScript(result);
}
else
{
script = buildReturnScript(0);
}
return script;
}