Browse Source

OSS中的image展示问题

pull/1/head
richie 6 years ago
parent
commit
f186d53871
  1. 1
      plugin.xml
  2. 43
      src/main/java/com/fr/plugin/file/download/oss/OssFile2Image.java

1
plugin.xml

@ -14,6 +14,7 @@
]]></change-notes> ]]></change-notes>
<extra-core> <extra-core>
<LocaleFinder class="com.fr.plugin.file.submit.oss.OssLocaleFinder"/> <LocaleFinder class="com.fr.plugin.file.submit.oss.OssLocaleFinder"/>
<FunctionDefineProvider class="com.fr.plugin.file.download.oss.OssFile2Image" name="OssFile2Image" description="将OSS中的文件以图片的形式展示到报表中。调用示例:OssFile2Image(key, bucket)。"/>
</extra-core> </extra-core>
<extra-decision> <extra-decision>
<HttpHandlerProvider class="com.fr.plugin.file.submit.oss.OssRequestHandler"/> <HttpHandlerProvider class="com.fr.plugin.file.submit.oss.OssRequestHandler"/>

43
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;
}
}
}
Loading…
Cancel
Save