response文件流是预览还是下载的区别
加上
response.setHeader("Content-Disposition", getFileName(file, request)); response.setContentType("application/force-download");
表示只能下载 不能预览
完整的下载代码如下:
@ApiOperation("下载文件") @GetMapping(value = "/downLoad", name = "下载文件") public void downLoad(@RequestParam String fileUrl, HttpServletRequest request, HttpServletResponse response) { File file = fileService.selectFileByFileUrl(fileUrl); minioUtil.downResponse(file, request, response); }
@SneakyThrows public void downResponse(com.ruoyi.bridge.manager.domain.File file, HttpServletRequest request, HttpServletResponse response) { if (file == null || file.getFileUrl() == null) { return; } GetObjectResponse object = minioClient.getObject(GetObjectArgs.builder() .bucket(minioConfig.getBucketName()) .object(file.getFileUrl()) .build()); StatObjectResponse objectInfo = minioClient.statObject(StatObjectArgs.builder() .bucket(minioConfig.getBucketName()) .object(file.getFileUrl()) .build()); // response.setHeader("Content-Disposition", getFileName(file, request)); // response.setContentType("application/force-download"); // todo lcx contentType // String contentType = MediaTypeFactory.getMediaType(file.getFileUrl()).orElse(MediaType.APPLICATION_OCTET_STREAM).toString(); // response.setContentType(contentType); response.setContentLengthLong(objectInfo.size()); response.setContentType(objectInfo.contentType()); // response.setCharacterEncoding("UTF-8"); IOUtils.copy(object, response.getOutputStream()); }
标签:预览,object,request,流是,file,getFileUrl,response,下载 From: https://www.cnblogs.com/LcxSummer/p/17516193.html