首页 > 解决方案 > REST Endpoint 总是在 POSTMAN 中下载图像两次

问题描述

在 POSTMAN 中使用时,Spring boot REST Endpoint 总是下载两次图像。内联/附件也不起作用,即使用作内联也总是下载它。这不是 stackoverflow 中的重复问题,因为它总是下载图像两次。

  1. 内联代码:
File invoiceImage = invoiceService.getInvoiceImage(id);
        return ResponseEntity
                .ok().header("Content-Disposition", "inline; filename=" +invoiceImage.getName()).
                contentType(MediaType.valueOf(Files.probeContentType(invoiceImage.toPath())))
                .body(Files.readAllBytes(invoiceImage.toPath()));

2.附件代码:

File invoiceImage = invoiceService.getInvoiceImage(id);
        return ResponseEntity
                .ok().header("Content-Disposition", "attachment; filename=" +invoiceImage.getName()).
                contentType(MediaType.valueOf(Files.probeContentType(invoiceImage.toPath())))
                .body(Files.readAllBytes(invoiceImage.toPath()));

标签: javaspringrestspring-boot

解决方案


推荐阅读