| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.apache.velocity.runtime.directive.Foreach; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | |
| | | import java.io.File; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 客户端版本控制APP上传 |
| | | * @param request |
| | | * @return AjaxResult |
| | | * @throws Exception |
| | | */ |
| | | @PostMapping("/tr/upload") |
| | | @ResponseBody |
| | | public AjaxResult uploadImgForSpread(MultipartFile file) throws Exception { |
| | | public AjaxResult uploadImgForSpread(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| | | try { |
| | | // 上传文件路径 |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | Iterator<String> iter = multipartRequest.getFileNames(); |
| | | String filePath = RuoYiConfig.getUploadPath(); |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("imageName", fileName); |
| | | ajax.put("imageUrl", url); |
| | | |
| | | return ajax; |
| | | while (iter.hasNext()) { |
| | | List<MultipartFile> files = multipartRequest.getFiles(iter.next()); |
| | | for (MultipartFile file : files) { |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | ajax.put("imageName", fileName); |
| | | ajax.put("imageUrl", url); |
| | | return ajax; |
| | | } |
| | | } |
| | | return AjaxResult.error("未获取到上传文件"); |
| | | |
| | | } catch (Exception e) { |
| | | return AjaxResult.error(e.getMessage()); |
| | | } |