| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | */ |
| | | @PostMapping("/common/upload") |
| | | public AjaxResult uploadFile(MultipartFile file) throws Exception { |
| | | int tomcatPort = getTomcatPort(); |
| | | //这个省人民是8099,所以直接写死 |
| | | int tomcatPort = 8099; |
| | | try { |
| | | // 上传文件路径 |
| | | String filePath = RuoYiConfig.getUploadPath(); |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | String url1 = serverConfig.getUrl(); |
| | | log.info("url1的值old :{}", url1); |
| | | //这里的8032不是tomcat的,所以要转成tomcat的 |
| | | url1.replaceAll("8099", "8032"); |
| | | log.info("url1的值new :{}", url1); |
| | | String url = url1 + fileName; |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("fileName", fileName); |
| | | ajax.put("url", url); |
| | |
| | | } |
| | | } |
| | | |
| | | private static int getTomcatPort() { |
| | | int port = 0; |
| | | Tomcat tomcat = new Tomcat(); |
| | | Connector connector = tomcat.getConnector(); |
| | | if (connector != null) { |
| | | AbstractProtocol protocol = (AbstractProtocol) connector.getProtocolHandler(); |
| | | port = protocol.getPort(); |
| | | } |
| | | return port; |
| | | } |
| | | |
| | | /** |
| | | * 本地资源通用下载 |