|
@@ -1,65 +1,26 @@
|
|
package com.dragon.tj.portal.controller;
|
|
package com.dragon.tj.portal.controller;
|
|
|
|
|
|
import com.dragon.tj.portal.common.base.R;
|
|
import com.dragon.tj.portal.common.base.R;
|
|
-import com.dragon.tj.portal.common.util.UploadUtils;
|
|
|
|
|
|
+import com.dragon.tj.portal.service.FileManageService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
-import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.net.InetAddress;
|
|
|
|
-import java.net.UnknownHostException;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
-@RequestMapping("/file")
|
|
|
|
|
|
+@RequestMapping("/fileMge")
|
|
public class FileManageController {
|
|
public class FileManageController {
|
|
|
|
|
|
- @Value("${dragon.file.path}")
|
|
|
|
- private String localPath;
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private ApplicationContext applicationContext;
|
|
|
|
|
|
+ private FileManageService fileManageService;
|
|
|
|
|
|
@PostMapping("/upload/{type}")
|
|
@PostMapping("/upload/{type}")
|
|
- public R upload(MultipartFile file, @PathVariable("type")String type){
|
|
|
|
-
|
|
|
|
- String originalFilename = file.getOriginalFilename();
|
|
|
|
- System.out.println(originalFilename);
|
|
|
|
-
|
|
|
|
- String uuidFilename = UploadUtils.getUUIDName(originalFilename);
|
|
|
|
-
|
|
|
|
- File dateDir = new File(localPath + type);
|
|
|
|
- if (!dateDir.exists()) {
|
|
|
|
- dateDir.mkdirs();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- File newFile = new File(dateDir.getPath(),uuidFilename);
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- file.transferTo(newFile);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- return R.failed().setMsg(e.getMessage());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Map<String,String> res = new HashMap<>();
|
|
|
|
- try {
|
|
|
|
- String hostAddress = InetAddress.getLocalHost().getHostAddress();
|
|
|
|
- String port = applicationContext.getEnvironment().getProperty("server.port");
|
|
|
|
- res.put("url","http://"+ hostAddress + ":" + port + "/file/" + type + "/" +uuidFilename);
|
|
|
|
- } catch (UnknownHostException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ public R upload(MultipartFile file, @PathVariable("type")Integer type){
|
|
|
|
|
|
- return R.ok().setData(res).setMsg("okk");
|
|
|
|
|
|
+ return R.ok().setData(fileManageService.upload(file,type));
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|