|
@@ -6,9 +6,12 @@ import cn.hutool.json.JSONUtil;
|
|
|
|
|
|
|
|
import com.aliyun.oss.OSS;
|
|
import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClient;
|
|
import com.aliyun.oss.OSSClient;
|
|
|
|
|
+import com.aliyun.oss.OSSException;
|
|
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
|
|
|
|
+import com.aliyun.oss.common.utils.IOUtils;
|
|
|
import com.aliyun.oss.internal.OSSUtils;
|
|
import com.aliyun.oss.internal.OSSUtils;
|
|
|
import com.aliyun.oss.model.*;
|
|
import com.aliyun.oss.model.*;
|
|
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
import com.zhongzheng.common.constant.Constants;
|
|
import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.domain.AjaxResult;
|
|
import com.zhongzheng.common.core.domain.AjaxResult;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
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.ClassPeriodStudentExportVo;
|
|
|
import com.zhongzheng.modules.grade.vo.WeekDataVo;
|
|
import com.zhongzheng.modules.grade.vo.WeekDataVo;
|
|
|
import com.zhongzheng.modules.user.service.IUserStudyRecordPhotoService;
|
|
import com.zhongzheng.modules.user.service.IUserStudyRecordPhotoService;
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.apache.xmlbeans.impl.values.XmlValueNotNillableException;
|
|
import org.apache.xmlbeans.impl.values.XmlValueNotNillableException;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -242,9 +244,8 @@ public class OssServiceImpl implements OssService {
|
|
|
//获取上传文件输入流
|
|
//获取上传文件输入流
|
|
|
InputStream inputStream = file.getFile().getInputStream();
|
|
InputStream inputStream = file.getFile().getInputStream();
|
|
|
String originalFilename = file.getFile().getOriginalFilename();
|
|
String originalFilename = file.getFile().getOriginalFilename();
|
|
|
- String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
|
|
|
|
|
|
|
|
|
|
- String fileName = ALIYUN_OSS_DIR_PREFIX + generateRandomFilename(file) + "." + suffix;
|
|
|
|
|
|
|
+ String fileName = ALIYUN_OSS_DIR_PREFIX + generateRandomFilename(file) ;
|
|
|
|
|
|
|
|
//调用oss方法实现上传
|
|
//调用oss方法实现上传
|
|
|
//第一个参数 Bucket名称
|
|
//第一个参数 Bucket名称
|
|
@@ -344,6 +345,32 @@ public class OssServiceImpl implements OssService {
|
|
|
return ossObject.getObjectContent();
|
|
return ossObject.getObjectContent();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void processObject(String targetImage,String sourceImage, String styleType) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ StringBuilder sbStyle = new StringBuilder();
|
|
|
|
|
+ Formatter styleFormatter = new Formatter(sbStyle);
|
|
|
|
|
+ styleFormatter.format("%s|sys/saveas,o_%s,b_%s", styleType,
|
|
|
|
|
+ BinaryUtil.toBase64String(targetImage.getBytes()),
|
|
|
|
|
+ BinaryUtil.toBase64String(ALIYUN_OSS_BUCKET_NAME.getBytes()));
|
|
|
|
|
+ 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();
|
|
|
|
|
+ } 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 {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void zipFile(List<String> fileList, ZipOutputStream zipOut,String dir) {
|
|
public void zipFile(List<String> fileList, ZipOutputStream zipOut,String dir) {
|
|
|
if (CollectionUtils.isEmpty(fileList)) {
|
|
if (CollectionUtils.isEmpty(fileList)) {
|
|
|
return;
|
|
return;
|