在POSTMAN中使用Spring Boot REST Endpoint时,它总是会下载映像两次。内联/附件也不起作用,即使用作内联,也始终会下载它。这不是stackoverflow中的重复问题,因为它总是下载映像两次。
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()));