Java OSS图片预览接口 2020-06-20 Java 阅读量 网关统一鉴权方式如Header中Authorization鉴权 123456789101112131415161718@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); }} 123456789101112131415161718@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