mirror of
https://github.com/Hello-hao/Tbed.git
synced 2024-04-21 12:32:10 +00:00
📝
This commit is contained in:
@@ -8,6 +8,7 @@ import com.netease.cloud.auth.BasicCredentials;
|
||||
import com.netease.cloud.auth.Credentials;
|
||||
import com.netease.cloud.services.nos.NosClient;
|
||||
import com.netease.cloud.services.nos.model.ObjectListing;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
@@ -18,20 +19,19 @@ public class NOSImageupload {
|
||||
static NosClient nosClient;
|
||||
static Keys key;
|
||||
|
||||
public ReturnImage Imageupload(Map<String, File> fileMap, String username,Integer keyID){
|
||||
public ReturnImage Imageupload(Map<Map<String, String>, File> fileMap, String username,Integer keyID){
|
||||
ReturnImage returnImage = new ReturnImage();
|
||||
File file = null;
|
||||
try {
|
||||
for (Map.Entry<String, File> entry : fileMap.entrySet()) {
|
||||
String ShortUID = SetText.getShortUuid();
|
||||
for (Map.Entry<Map<String, String>, File> entry : fileMap.entrySet()) {
|
||||
String prefix = entry.getKey().get("prefix");
|
||||
String ShortUIDName = entry.getKey().get("name");
|
||||
file = entry.getValue();
|
||||
nosClient.putObject(key.getBucketname(), username + "/" + ShortUID+ "." + entry.getKey(), file);
|
||||
returnImage.setImgname(username + "/" + ShortUID+ "." + entry.getKey());
|
||||
returnImage.setImgurl(key.getRequestAddress() + "/" + username + "/" + ShortUID + "." + entry.getKey());
|
||||
returnImage.setImgSize(entry.getValue().length());
|
||||
returnImage.setCode("200");
|
||||
nosClient.putObject(
|
||||
key.getBucketname(), username + "/" + ShortUIDName + "." + prefix, file);
|
||||
}
|
||||
}catch (Exception e){
|
||||
returnImage.setCode("200");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
returnImage.setCode("500");
|
||||
}
|
||||
@@ -42,25 +42,25 @@ public class NOSImageupload {
|
||||
|
||||
public static Integer Initialize(Keys k) {
|
||||
int ret = -1;
|
||||
if(k.getEndpoint()!=null && k.getAccessSecret()!=null && k.getEndpoint()!=null
|
||||
&& k.getBucketname()!=null && k.getRequestAddress()!=null ){
|
||||
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("")
|
||||
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ){
|
||||
// 初始化
|
||||
Credentials credentials = new BasicCredentials(k.getAccessKey(), k.getAccessSecret());
|
||||
NosClient nosObj = new NosClient(credentials);
|
||||
nosObj.setEndpoint(k.getEndpoint());
|
||||
ObjectListing objectListing = null;
|
||||
try {
|
||||
objectListing = nosObj.listObjects(k.getBucketname());
|
||||
ret = 1;
|
||||
nosClient = nosObj;
|
||||
key = k;
|
||||
}catch (Exception e){
|
||||
System.out.println("NOS 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;
|
||||
}
|
||||
Credentials credentials = new BasicCredentials(k.getAccessKey(), k.getAccessSecret());
|
||||
NosClient nosObj = new NosClient(credentials);
|
||||
nosObj.setEndpoint(k.getEndpoint());
|
||||
ObjectListing objectListing = null;
|
||||
try {
|
||||
objectListing = nosObj.listObjects(k.getBucketname());
|
||||
ret = 1;
|
||||
nosClient = nosObj;
|
||||
key = k;
|
||||
}catch (Exception e){
|
||||
System.out.println("NOS Object Is null");
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user