richie
6 years ago
2 changed files with 44 additions and 0 deletions
@ -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…
Reference in new issue