From f186d538714f3373af0b1b45bff7c0bf0544047f Mon Sep 17 00:00:00 2001 From: richie Date: Tue, 6 Nov 2018 16:23:22 +0800 Subject: [PATCH] =?UTF-8?q?OSS=E4=B8=AD=E7=9A=84image=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 1 + .../file/download/oss/OssFile2Image.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/com/fr/plugin/file/download/oss/OssFile2Image.java diff --git a/plugin.xml b/plugin.xml index 228dca6..818a743 100644 --- a/plugin.xml +++ b/plugin.xml @@ -14,6 +14,7 @@ ]]> + diff --git a/src/main/java/com/fr/plugin/file/download/oss/OssFile2Image.java b/src/main/java/com/fr/plugin/file/download/oss/OssFile2Image.java new file mode 100644 index 0000000..1ca2465 --- /dev/null +++ b/src/main/java/com/fr/plugin/file/download/oss/OssFile2Image.java @@ -0,0 +1,43 @@ +package com.fr.plugin.file.download.oss; + +import com.aliyun.oss.OSSClient; +import com.aliyun.oss.model.OSSObject; +import com.fr.general.GeneralUtils; +import com.fr.general.IOUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.plugin.file.submit.oss.conf.FileSubmitOssServerConfig; +import com.fr.script.AbstractFunction; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Primitive; + +import javax.imageio.ImageIO; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +/** + * 将OSS中的文件已图片的方式展示到报表中来 + */ +public class OssFile2Image extends AbstractFunction { + + @Override + public Object run(Object[] args) { + int len = ArrayUtils.getLength(args); + if (len < 2) { + return Primitive.ERROR_VALUE; + } + String key = GeneralUtils.objectToString(args[0]); + String bucket = GeneralUtils.objectToString(args[1]); + OSSClient ossClient = new OSSClient( + FileSubmitOssServerConfig.getInstance().getEndPoint(), + FileSubmitOssServerConfig.getInstance().getAccessKeyId(), + FileSubmitOssServerConfig.getInstance().getAccessKeySecret()); + OSSObject object = ossClient.getObject(bucket, key); + byte[] bytes = IOUtils.inputStream2Bytes(object.getObjectContent()); + try { + return ImageIO.read(new ByteArrayInputStream(bytes)); + } catch (IOException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + return Primitive.ERROR_VALUE; + } + } +}