首页 > 其他分享 >response文件流是预览还是下载的区别

response文件流是预览还是下载的区别

时间:2023-06-30 11:33:46浏览次数:46  
标签:预览 object request 流是 file getFileUrl response 下载

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

相关文章

  • docker报错:Error response from daemon: driver failed programming external connect
    重启docker-compose时,nginx服务报错。报错信息:Errorresponsefromdaemon:driverfailedprogrammingexternalconnectivityonendpointlikeshop-nginx(f0a809481f5016e6f7ca6e1ed826b0676d5523b15f2954a2d22c03c12a89567d):Bindfor0.0.0.0:80failed:portisalr......
  • chrome.runtime.onMessage.addListener sendResponse
    Ifmultiplepagesarelisteningfor onMessage events,onlythefirsttocall sendResponse() foraparticulareventwillsucceedinsendingtheresponse.Allotherresponsestothateventwillbeignored.如果多个页面正在监听onMessage事件,则只有第一个为特定......
  • ModifyAjaxResponse,修改ajax请求返回值,前后端调试之利器
    一、概要先看图 京豆多的离谱,你的第一想法肯定是:按F12修改了网页元素没那么简单,你看支持刷新的  肯定还是假的,通过Fiddler或Wireshark等抓包工具修改了响应包;或者干脆改了本地host文件,指向了一个自己写的页面......这些都太麻烦了,如果能在当前网页上拦截这个请求,......
  • 图片预览
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>Document</title><......
  • Response响应字节数据
         ......
  • Response响应字符数据
        ......
  • 前端封装excel下载方法&&解决前端下载请求设置responseType: 'blob'时后台报错无法处
    请求设置responseType:'blob'时接口报错了如果不做处理则获取不到接口错误信息,此时下载的文件是有问题的。/*@paramsoptions{}*data:Blob,*fileName:String,*successMsg:String,**/import{Message}from'element-ui'importdownloadExcelFilePublicHandler......
  • dbca -silent -responsefile 建库由于tmpfs太小报错ORA-27102: out of memory
    错误信息:[oracle@db01~]$dbca-silent-responsefiledbca.rspCopyingdatabasefiles1%complete2%complete4%complete12%complete100%completeLookatthelogfile"/DBSoft/oracle/cfgtoollogs/dbca/woo/woo.log"forfurtherdetails.[oracle@db01......
  • edge预览版下载
    edge下载https://www.microsoft.com/zh-cn/edge/download/insider......
  • Vue单项数据流是什么
    父级prop的更新会向下流动到子组件中,但是反过来则不行,防止从子组件意外改变父级组件的状态每次父级组件发生更新时,子组件中所有的prop都将会刷新为最新的值子组件想修改时,只能通过$emit派发一个自定义事件,父组件接收到后,由父组件修改 ......