|
|
|
package com.fr.plugin.file.download.oss;
|
|
|
|
|
|
|
|
import com.aliyun.oss.OSS;
|
|
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
|
|
import com.aliyun.oss.model.OSSObject;
|
|
|
|
import com.fanruan.api.log.LogKit;
|
|
|
|
import com.fanruan.api.util.ArrayKit;
|
|
|
|
import com.fanruan.api.util.GeneralKit;
|
|
|
|
import com.fanruan.api.util.IOKit;
|
|
|
|
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
|
|
|
|
import com.fr.script.AbstractFunction;
|
|
|
|
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 = ArrayKit.getLength(args);
|
|
|
|
if (len < 2) {
|
|
|
|
return Primitive.ERROR_VALUE;
|
|
|
|
}
|
|
|
|
String key = GeneralKit.objectToString(args[0]);
|
|
|
|
String bucket = GeneralKit.objectToString(args[1]);
|
|
|
|
OSS ossClient = new OSSClientBuilder().build(
|
|
|
|
OssUniversalConfig.getInstance().getEndPoint(),
|
|
|
|
OssUniversalConfig.getInstance().getAccessKeyId(),
|
|
|
|
OssUniversalConfig.getInstance().getRealAccessKeySecret());
|
|
|
|
OSSObject object = ossClient.getObject(bucket, key);
|
|
|
|
byte[] bytes = IOKit.inputStream2Bytes(object.getObjectContent());
|
|
|
|
try {
|
|
|
|
return ImageIO.read(new ByteArrayInputStream(bytes));
|
|
|
|
} catch (IOException e) {
|
|
|
|
LogKit.error(e.getMessage(), e);
|
|
|
|
return Primitive.ERROR_VALUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|