| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 通用请求处理 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @RestController |
| | |
| | | |
| | | /** |
| | | * 通用下载请求 |
| | | * |
| | | * |
| | | * @param fileName 文件名称 |
| | | * @param delete 是否删除 |
| | | */ |
| | |
| | | |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, realFileName); |
| | | FileUtils.writeBytes(filePath, response.getOutputStream()); |
| | | FileUtils.writeToStream(filePath, response.getOutputStream()); |
| | | if (delete) |
| | | { |
| | | FileUtils.deleteFile(filePath); |
| | | FileUtils.del(filePath); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | |
| | | // 上传并返回新文件名称 |
| | | String fileName = FileUploadUtils.upload(filePath, file); |
| | | String url = serverConfig.getUrl() + fileName; |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | Map<String,Object> ajax = new HashMap<>(); |
| | | ajax.put("fileName", fileName); |
| | | ajax.put("url", url); |
| | | return ajax; |
| | | return AjaxResult.success(ajax); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | String downloadName = StrUtil.subAfter(downloadPath, "/",true); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, downloadName); |
| | | FileUtils.writeBytes(downloadPath, response.getOutputStream()); |
| | | FileUtils.writeToStream(downloadPath, response.getOutputStream()); |
| | | } |
| | | catch (Exception e) |
| | | { |