Java Code Examples for com.ruoyi.common.utils.file.FileUtils#writeBytes()
The following examples show how to use
com.ruoyi.common.utils.file.FileUtils#writeBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonController.java From RuoYi-Vue with MIT License | 6 votes |
/** * 本地资源通用下载 */ @GetMapping("/common/download/resource") public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception { // 本地资源路径 String localPath = RuoYiConfig.getProfile(); // 数据库资源地址 String downloadPath = localPath + StringUtils.substringAfter(name, Constants.RESOURCE_PREFIX); // 下载名称 String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName)); FileUtils.writeBytes(downloadPath, response.getOutputStream()); }
Example 2
Source File: CommonController.java From ruoyiplus with MIT License | 6 votes |
/** * 通用下载请求 * * @param fileName 文件名称 * @param delete 是否删除 */ @GetMapping("common/download") public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); try { String filePath = Global.getDownloadPath() + fileName; response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + setFileDownloadHeader(request, realFileName)); FileUtils.writeBytes(filePath, response.getOutputStream()); if (delete) { FileUtils.deleteFile(filePath); } } catch (Exception e) { log.error("下载文件失败", e); } }
Example 3
Source File: CommonController.java From RuoYi with Apache License 2.0 | 6 votes |
@RequestMapping("common/download") @ApiOperation(value = "通用下载文件") @ApiImplicitParams({ @ApiImplicitParam(name = "fileName",value = "文件名",required = true), @ApiImplicitParam(name = "delete",value = "是否删除临时文件",required = true,dataType ="boolean") }) public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf('_') + 1); try { if (!FileUtils.isValidFilename(fileName)){ throw new BusinessException(String.format(" 文件名称(%s)非法,不允许下载。 ", fileName)); } String filePath = Global.getDownloadPath() + fileName; response.setCharacterEncoding(CharsetKit.UTF8); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName)); FileUtils.writeBytes(filePath, response.getOutputStream()); if (delete) { FileUtils.deleteFile(filePath); } } catch (Exception e) { log.error("下载文件失败", e); } }
Example 4
Source File: CommonController.java From supplierShop with MIT License | 5 votes |
/** * 通用下载请求 * * @param fileName 文件名称 * @param delete 是否删除 */ @GetMapping("common/download") public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { try { if (!FileUtils.isValidFilename(fileName)) { throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName)); } String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); String filePath = Global.getDownloadPath() + fileName; response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName)); FileUtils.writeBytes(filePath, response.getOutputStream()); if (delete) { FileUtils.deleteFile(filePath); } } catch (Exception e) { log.error("下载文件失败", e); } }
Example 5
Source File: CommonController.java From RuoYi-Vue with MIT License | 5 votes |
/** * 通用下载请求 * * @param fileName 文件名称 * @param delete 是否删除 */ @GetMapping("common/download") public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { try { if (!FileUtils.isValidFilename(fileName)) { throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName)); } String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); String filePath = RuoYiConfig.getDownloadPath() + fileName; response.setCharacterEncoding("utf-8"); response.setContentType("multipart/form-data"); response.setHeader("Content-Disposition", "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName)); FileUtils.writeBytes(filePath, response.getOutputStream()); if (delete) { FileUtils.deleteFile(filePath); } } catch (Exception e) { log.error("下载文件失败", e); } }