mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
:art:完善部分新功能
This commit is contained in:
@@ -4,14 +4,13 @@ import cn.hellohao.pojo.Images;
|
||||
import cn.hellohao.pojo.Keys;
|
||||
import cn.hellohao.pojo.Msg;
|
||||
import cn.hellohao.pojo.ReturnImage;
|
||||
import cn.hellohao.utils.SetText;
|
||||
import cn.hellohao.utils.TypeDict;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.ObjectListing;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
@@ -22,7 +21,8 @@ public class OSSImageupload {
|
||||
static OSS ossClient;
|
||||
static Keys key;
|
||||
|
||||
public ReturnImage ImageuploadOSS(Map<Map<String, String>, File> fileMap, String username,Integer keyID){
|
||||
public ReturnImage ImageuploadOSS(
|
||||
Map<Map<String, String>, File> fileMap, String username, Integer keyID) {
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
File file = null;
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
@@ -53,27 +53,31 @@ public class OSSImageupload {
|
||||
public static Integer Initialize(Keys k) {
|
||||
int ret = -1;
|
||||
ObjectListing objectListing = null;
|
||||
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getAccessKey()!=null && k.getEndpoint()!=null
|
||||
&& k.getBucketname()!=null && k.getRequestAddress()!=null ) {
|
||||
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getAccessKey().equals("") && !k.getEndpoint().equals("")
|
||||
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ) {
|
||||
OSS ossObj = new OSSClientBuilder().build(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
|
||||
try {
|
||||
objectListing = ossObj.listObjects(k.getBucketname());
|
||||
ret=1;
|
||||
ossClient = ossObj;
|
||||
key = k;
|
||||
} catch (Exception e) {
|
||||
System.out.println("OSS Object Is null");
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(k.getAccessKey())
|
||||
|| StringUtils.isBlank(k.getAccessSecret())
|
||||
|| StringUtils.isBlank(k.getEndpoint())
|
||||
|| StringUtils.isBlank(k.getBucketname())
|
||||
|| StringUtils.isBlank(k.getRequestAddress())) {
|
||||
return -1;
|
||||
}
|
||||
OSS ossObj =
|
||||
new OSSClientBuilder()
|
||||
.build(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
|
||||
try {
|
||||
objectListing = ossObj.listObjects(k.getBucketname());
|
||||
ret = 1;
|
||||
ossClient = ossObj;
|
||||
key = k;
|
||||
} catch (Exception e) {
|
||||
System.out.println("OSS Object Is null");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean delOSS(Integer keyID, Images images){
|
||||
boolean b =true;
|
||||
public boolean delOSS(Integer keyID, Images images) {
|
||||
boolean b = true;
|
||||
try {
|
||||
ossClient.deleteObject(key.getBucketname(), images.getImgname());
|
||||
} catch (Exception e) {
|
||||
@@ -82,6 +86,4 @@ public class OSSImageupload {
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user