Spring MVC下载文件, IE浏览器不支持

    @ApiOperation("图片下载")
    @GetMapping("/download")
    public ResponseEntity<byte[]> download(@RequestParam Long sbbId, @ApiParam("文件id") @RequestParam String fileId) throws IOException {
        BsptSbhcFile bsptSbhcFile = sbhcService.queryFile(sbbId, this.getCloudCompany().getCompanyId(), fileId);
        String path = url;
        String fileSuffix = (bsptSbhcFile.getFilepath().substring(bsptSbhcFile.getFilepath().lastIndexOf('.')));

        HttpStatus status = HttpStatus.OK;
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        headers.setContentDispositionFormData("attachment", bsptSbhcFile.getFilename() + fileSuffix);

        InputStream is = HttpUtils.dowloadFile(path);
        ByteArrayOutputStream writer = new ByteArrayOutputStream();
        byte[] buff = new byte[1024 * 2];
        int len;
        try {
            while ((len = is.read(buff)) != -1) {
                writer.write(buff, 0, len);
            }
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        byte[] bytes = writer.toByteArray();
        return new ResponseEntity<>(bytes, headers, status);
    }

问题:

谷歌下载正常,IE浏览器不能下载

 

原因:

IE 不支持201状态码,修改为200。

原来:
HttpStatus status = HttpStatus.CREATED;

修改为:
HttpStatus status = HttpStatus.OK;

 

 

 


版权声明:本文为haoui123原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。