Java OSS图片预览接口

网关统一鉴权方式

HeaderAuthorization鉴权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@GetMapping(value = "/image/view")
public void downloadDoc(@RequestParam("filePath") String filePath, HttpServletResponse response) {

log.info("download image. filePath={}", filePath);
try (OutputStream outputStream = response.getOutputStream()){
Result<byte[]> file = fileRpcApi.download(filePath);
if (file.fail()) {
response.getOutputStream().write(JSON.
toJSONString(ResultBuilder.failure(ResponseCode.NOT_FOUND, "file not found"))
.getBytes());
return;
}
response.setContentType("image/jpeg;charset=utf-8");
outputStream.write(file.getData());
} catch (Exception e) {
log.error("", e);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@GetMapping(value = "/image/viewMulti")
@SuppressWarnings("unchecked")
public Result<List<String>> viewDoc(@RequestParam(value = "filePath", required = false) String filePath) {
if (isBlank(filePath)) {
return ResultBuilder.failure(ResponseCode.BAD_REQUEST, "filePath is empty!");
}
List<String> list = new ArrayList<>(3);
Arrays.stream(filePath.split(",|;")).map(p -> p.trim()).forEach(p -> {
Result<byte[]> file = fileRpcApi.download(p);
if (file.fail()) {
log.warn("file[{}] download fail", p);
return;
}
list.add(Base64.getEncoder().encodeToString(file.getData()));
});

return ResultBuilder.success(list);
}

token鉴权方式

如:https://www.appblog.cn/image?token=xxxxxx

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :