|
@@ -1,8 +1,11 @@
|
|
|
package org.dbsyncer.web.controller.upload;
|
|
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.dbsyncer.biz.PluginService;
|
|
|
import org.dbsyncer.biz.vo.RestResult;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -11,6 +14,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.File;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping("/upload")
|
|
@@ -23,7 +27,9 @@ public class UploadController {
|
|
|
return "upload/upload";
|
|
|
}
|
|
|
|
|
|
- //@PreAuthorize("hasAuthority('ROLE_')")
|
|
|
+ @Autowired
|
|
|
+ private PluginService pluginService;
|
|
|
+
|
|
|
@RequestMapping(value = "/upload")
|
|
|
@ResponseBody
|
|
|
public RestResult upload(HttpServletRequest request, @RequestParam("file") MultipartFile[] files) {
|
|
@@ -31,10 +37,14 @@ public class UploadController {
|
|
|
if (files != null) {
|
|
|
int length = files.length;
|
|
|
MultipartFile file = null;
|
|
|
+ String filePath = pluginService.getPluginPath();
|
|
|
+ FileUtils.forceMkdir(new File(filePath));
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
file = files[i];
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
- System.out.println(fileName);
|
|
|
+ if (file != null) {
|
|
|
+ File dest = new File(filePath + file.getOriginalFilename());
|
|
|
+ FileUtils.copyInputStreamToFile(file.getInputStream(), dest);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return RestResult.restSuccess("ok");
|