java Spring RestController返回错误的内容类型
我试图通过以下方式返回Spring RestController中的图像:
@GetMapping(path = "/images/{imageKey:.+}")
public ResponseEntity<Resource> getImageAsResource(
@PathVariable("imageKey") String imageKey) {
Resource resource = resourceService.getImage(imageKey);
return ResponseEntity.ok(resource);
}
resourceService
将图像作为Java资源对象返回。然而,Spring根据生成的HTTP响应中的资源,将Content-Type:
设置为application/json
,而不是正确的image/...
类型。
如何让Spring从返回的资源中推断出正确的内容类型?
返回的图像资源可以是PNG、JPG或GIF
共 (0) 个答案