|
@@ -6,9 +6,12 @@ import cn.hutool.json.JSONUtil;
|
|
|
|
|
|
import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
+import com.aliyun.oss.OSSException;
|
|
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
|
|
+import com.aliyun.oss.common.utils.IOUtils;
|
|
|
import com.aliyun.oss.internal.OSSUtils;
|
|
|
import com.aliyun.oss.model.*;
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.domain.AjaxResult;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
@@ -20,7 +23,6 @@ import com.zhongzheng.modules.alioss.vo.ResultBean;
|
|
|
import com.zhongzheng.modules.grade.vo.ClassPeriodStudentExportVo;
|
|
|
import com.zhongzheng.modules.grade.vo.WeekDataVo;
|
|
|
import com.zhongzheng.modules.user.service.IUserStudyRecordPhotoService;
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.xmlbeans.impl.values.XmlValueNotNillableException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -343,6 +345,39 @@ public class OssServiceImpl implements OssService {
|
|
|
return ossObject.getObjectContent();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void processObject(String targetImage,String sourceImage, String styleType) {
|
|
|
+ try {
|
|
|
+ // 将图片缩放为固定宽高100 px。
|
|
|
+ StringBuilder sbStyle = new StringBuilder();
|
|
|
+ Formatter styleFormatter = new Formatter(sbStyle);
|
|
|
+ // 将处理后的图片命名为example-resize.png并保存到当前Bucket。
|
|
|
+ // 填写Object完整路径。Object完整路径中不能包含Bucket名称。
|
|
|
+ styleFormatter.format("%s|sys/saveas,o_%s,b_%s", styleType,
|
|
|
+ BinaryUtil.toBase64String(targetImage.getBytes()),
|
|
|
+ BinaryUtil.toBase64String(ALIYUN_OSS_BUCKET_NAME.getBytes()));
|
|
|
+ System.out.println(sbStyle.toString());
|
|
|
+ ProcessObjectRequest request = new ProcessObjectRequest(ALIYUN_OSS_BUCKET_NAME, sourceImage, sbStyle.toString());
|
|
|
+ GenericResult processResult = ossClient.processObject(request);
|
|
|
+ String json = IOUtils.readStreamAsString(processResult.getResponse().getContent(), "UTF-8");
|
|
|
+ processResult.getResponse().getContent().close();
|
|
|
+ System.out.println(json);
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
|
+ + "but was rejected with an error response for some reason.");
|
|
|
+ System.out.println("Error Message:" + oe.getErrorMessage());
|
|
|
+ System.out.println("Error Code:" + oe.getErrorCode());
|
|
|
+ System.out.println("Request ID:" + oe.getRequestId());
|
|
|
+ System.out.println("Host ID:" + oe.getHostId());
|
|
|
+ }catch (IOException e) {
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ if (ossClient != null) {
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void zipFile(List<String> fileList, ZipOutputStream zipOut,String dir) {
|
|
|
if (CollectionUtils.isEmpty(fileList)) {
|
|
|
return;
|