|
|
@ -1,11 +1,15 @@ |
|
|
|
package com.kms.web.controller.common; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
import com.jianwei.common.utils.FileUploadUtils; |
|
|
|
import com.kms.framework.config.ServerConfig; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -40,6 +44,9 @@ public class CommonController |
|
|
|
@Autowired |
|
|
|
private FastDfsUtil fastdfs; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ServerConfig serverConfig; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 通用下载请求 |
|
|
@ -85,10 +92,12 @@ public class CommonController |
|
|
|
@PostMapping("/common/upload") |
|
|
|
public AjaxResult uploadFile(MultipartFile file) throws Exception |
|
|
|
{ |
|
|
|
String uploadType = JianweiConfig.getUploadType(); |
|
|
|
try |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (uploadType.equals("FastDFS")) { |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
|
|
|
|
// 上传并返回文件名称
|
|
|
@ -97,9 +106,23 @@ public class CommonController |
|
|
|
ajax.put("fileName", fileName); |
|
|
|
ajax.put("url", uploadFile); |
|
|
|
return ajax; |
|
|
|
} else { |
|
|
|
// 上传文件路径
|
|
|
|
String localPath = JianweiConfig.getProfile(); |
|
|
|
// 上传并返回新文件名称
|
|
|
|
String fileName = FileUploadUtils.upload(localPath, file); |
|
|
|
String url = serverConfig.getUrl() + fileName; |
|
|
|
AjaxResult ajax = AjaxResult.success(); |
|
|
|
ajax.put("fileName", fileName); |
|
|
|
ajax.put("url", url); |
|
|
|
return ajax; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
return AjaxResult.error(e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
@ -121,6 +144,8 @@ public class CommonController |
|
|
|
response.setHeader("Content-Disposition", |
|
|
|
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName)); |
|
|
|
FileUtils.writeBytes(downloadPath, response.getOutputStream()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/logout") |
|
|
|