{"id":1509,"date":"2023-03-25T14:00:30","date_gmt":"2023-03-25T06:00:30","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1509"},"modified":"2023-04-28T20:21:34","modified_gmt":"2023-04-28T12:21:34","slug":"java-oss-image-preview-interface","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/java-oss-image-preview-interface\/","title":{"rendered":"Java OSS\u56fe\u7247\u9884\u89c8\u63a5\u53e3"},"content":{"rendered":"<h2>\u7f51\u5173\u7edf\u4e00\u9274\u6743\u65b9\u5f0f<\/h2>\n<p>\u5982<code>Header<\/code>\u4e2d<code>Authorization<\/code>\u9274\u6743<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">@GetMapping(value = &quot;\/image\/view&quot;)\npublic void downloadDoc(@RequestParam(&quot;filePath&quot;) String filePath, HttpServletResponse response) {\n\n    log.info(&quot;download image. filePath={}&quot;, filePath);\n    try (OutputStream outputStream = response.getOutputStream()){\n        Result&lt;byte[]&gt; file = fileRpcApi.download(filePath);\n        if (file.fail()) {\n            response.getOutputStream().write(JSON.\n                    toJSONString(ResultBuilder.failure(ResponseCode.NOT_FOUND, &quot;file not found&quot;))\n                    .getBytes());\n            return;\n        }\n        response.setContentType(&quot;image\/jpeg;charset=utf-8&quot;);\n        outputStream.write(file.getData());\n    } catch (Exception e) {\n        log.error(&quot;&quot;, e);\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-java\">@GetMapping(value = &quot;\/image\/viewMulti&quot;)\n@SuppressWarnings(&quot;unchecked&quot;)\npublic Result&lt;List&lt;String&gt;&gt; viewDoc(@RequestParam(value = &quot;filePath&quot;, required = false) String filePath) {\n    if (isBlank(filePath)) {\n        return ResultBuilder.failure(ResponseCode.BAD_REQUEST, &quot;filePath is empty!&quot;);\n    }\n    List&lt;String&gt; list = new ArrayList&lt;&gt;(3);\n    Arrays.stream(filePath.split(&quot;,|;&quot;)).map(p -&gt; p.trim()).forEach(p -&gt; {\n        Result&lt;byte[]&gt; file = fileRpcApi.download(p);\n        if (file.fail()) {\n            log.warn(&quot;file[{}] download fail&quot;, p);\n            return;\n        }\n        list.add(Base64.getEncoder().encodeToString(file.getData()));\n    });\n\n    return ResultBuilder.success(list);\n}<\/code><\/pre>\n<h2>token\u9274\u6743\u65b9\u5f0f<\/h2>\n<p>\u5982\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.appblog.cn\/image?token=xxxxxx\">https:\/\/www.appblog.cn\/image?token=xxxxxx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u5173\u7edf\u4e00\u9274\u6743\u65b9\u5f0f \u5982Header\u4e2dAuthorization\u9274\u6743 @GetMapping(value = &#038;q [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[246],"class_list":["post-1509","post","type-post","status-publish","format-standard","hentry","category-java-basic","tag-oss"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1509"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1509\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}