|
|
@@ -7,6 +7,7 @@ import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
import com.aliyun.oss.OSSClientBuilder;
|
|
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
|
|
+import com.aliyun.oss.internal.OSSUtils;
|
|
|
import com.aliyun.oss.model.MatchMode;
|
|
|
import com.aliyun.oss.model.PolicyConditions;
|
|
|
import com.aliyun.oss.model.PutObjectRequest;
|
|
|
@@ -27,11 +28,14 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Base64Utils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import sun.misc.BASE64Decoder;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.sql.rowset.serial.SerialBlob;
|
|
|
+import javax.sql.rowset.serial.SerialException;
|
|
|
import java.awt.*;
|
|
|
import java.io.*;
|
|
|
+import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
@@ -111,8 +115,7 @@ public class OssServiceImpl implements OssService {
|
|
|
int intDay = calCurrent.get(Calendar.DATE);
|
|
|
int intMonth = calCurrent.get(Calendar.MONTH) + 1;
|
|
|
int intYear = calCurrent.get(Calendar.YEAR);
|
|
|
- String now = String.valueOf(intYear) + "_" + String.valueOf(intMonth) + "_" +
|
|
|
- String.valueOf(intDay) + "_";
|
|
|
+ String now = String.valueOf(System.currentTimeMillis()) + "_";
|
|
|
|
|
|
RandomFilename = now + String.valueOf(random > 0 ? random : (-1) * random);
|
|
|
switch(ossRequest.getImageStatus()){
|
|
|
@@ -140,7 +143,6 @@ public class OssServiceImpl implements OssService {
|
|
|
}
|
|
|
|
|
|
return RandomFilename;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -182,4 +184,28 @@ public class OssServiceImpl implements OssService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String uploadBase64(String fileStr) {
|
|
|
+ try{
|
|
|
+ BASE64Decoder decoder = new BASE64Decoder();
|
|
|
+ byte[] imageByte = decoder.decodeBuffer(fileStr);
|
|
|
+ SerialBlob serialBlob = new SerialBlob(imageByte);
|
|
|
+ InputStream binaryStream = serialBlob.getBinaryStream();
|
|
|
+ OssRequest ossRequest = new OssRequest();
|
|
|
+ ossRequest.setImageStatus(1);
|
|
|
+ String fileName = generateRandomFilename(ossRequest);
|
|
|
+ PutObjectResult putObjectResult = ossClient.putObject(ALIYUN_OSS_BUCKET_NAME, fileName, binaryStream);
|
|
|
+ ossClient.shutdown();
|
|
|
+ return fileName;
|
|
|
+ }catch (SerialException throwables) {
|
|
|
+ throwables.printStackTrace();
|
|
|
+ } catch (SQLException throwables) {
|
|
|
+ throwables.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
}
|