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; + } + } +}