You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.5 KiB
43 lines
1.5 KiB
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.oss.universal.config.OssUniversalConfig; |
|
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( |
|
OssUniversalConfig.getInstance().getEndPoint(), |
|
OssUniversalConfig.getInstance().getAccessKeyId(), |
|
OssUniversalConfig.getInstance().getRealAccessKeySecret()); |
|
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; |
|
} |
|
} |
|
}
|
|
|