
使用 ResourceLoader 获取文件,请问我要怎么做才能让游览器直接显示成图片呢?
private final ResourceLoader resourceLoader; @RequestMapping(method = RequestMethod.GET, value = "/{filename:.+}") @ResponseBody public ResponseEntity<?> getFile(@PathVariable String filename) { try { return ResponseEntity.ok(resourceLoader.getResource("file:" + Paths.get(ROOT, filename).toString())); } catch (Exception e) { return ResponseEntity.notFound().build(); } } 1 CFO Aug 10, 2018 via Android 给流前端不太好处理吧 我的做法是存在文件服务器里给路径 小图直接 base64 给过去也行 |
2 kamil Aug 10, 2018 via iPhone RequestMapping 里的 produce 可以设置返回的 Content-Type 比如,image/jpg 把 ResponseEntity.ok 里的 toString 去掉,直接返回 |
3 elgae Aug 10, 2018 用 StreamingResponseBody 比较合适 |
4 limuyan44 Aug 10, 2018 via Android 手动把 reponse 的 contenttype 设为 octet-stream 就可以了。 |
6 zjp Aug 10, 2018 via Android 没运行代码,难道不是 2 楼才是正解吗 |