2019-08-07更新 增加API接口

This commit is contained in:
Hellohao
2019-08-07 23:22:44 +08:00
parent 77efdc9fa6
commit d777f42719
69 changed files with 7374 additions and 329 deletions
@@ -2,6 +2,7 @@ package cn.hellohao.service.impl;
import cn.hellohao.pojo.Keys;
import cn.hellohao.pojo.ReturnImage;
import cn.hellohao.pojo.UploadConfig;
import cn.hellohao.utils.ImgUrlUtil;
import cn.hellohao.utils.Print;
import com.aliyun.oss.OSSClient;
@@ -113,24 +114,28 @@ public class OSSImageupload {
}
//初始化
public static void Initialize(Keys k) {
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 ) {
// 初始化
// 创建OSSClient实例。
ossClient = new OSSClient(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
key = k;
if(!k.getEndpoint().equals("") && !k.getAccessSecret().equals("") && !k.getEndpoint().equals("")
&& !k.getBucketname().equals("") && !k.getRequestAddress().equals("") ) {
ossClient = new OSSClient(k.getEndpoint(), k.getAccessKey(), k.getAccessSecret());
key = k;
ret=1;
}
}
return ret;
}
/**
* 客户端接口
* */
public Map<String, Integer> clientuploadOSS(Map<String, MultipartFile> fileMap, String username) throws Exception {
public Map<ReturnImage, Integer> clientuploadOSS(Map<String, MultipartFile> fileMap, String username, UploadConfig uploadConfig) throws Exception {
File file = null;
Map<String, Integer> ImgUrl = new HashMap<>();
Map<ReturnImage, Integer> ImgUrl = new HashMap<>();
//设置Header
ObjectMetadata meta = new ObjectMetadata();
meta.setHeader("Content-Disposition", "inline");
@@ -153,14 +158,21 @@ public class OSSImageupload {
System.err.println("位置格式文件,无法定义header头。");
}
meta.setHeader("Content-Type", head);//image/jpeg
// 上传文件流。
System.out.println("待上传的图片:"+username + "/" + uuid+times + "." + entry.getKey());
ossClient.putObject(key.getBucketname(), username + "/" + uuid+times + "." + entry.getKey(),file,meta);
// 关闭OSSClient。
//ossClient.shutdown();
Print.Normal(entry.getValue().getSize());
ImgUrl.put(key.getRequestAddress() + "/" + username + "/" + uuid+times + "." + entry.getKey(), (int) (entry.getValue().getSize()/1024));
ReturnImage returnImage = new ReturnImage();
if(entry.getValue().getSize()/1024<=uploadConfig.getFilesizeuser()*1024){
// 上传文件流。
System.out.println("待上传的图片:"+username + "/" + uuid+times + "." + entry.getKey());
ossClient.putObject(key.getBucketname(), username + "/" + uuid+times + "." + entry.getKey(),file,meta);
returnImage.setImgname(entry.getValue().getOriginalFilename());
returnImage.setImgurl(key.getRequestAddress() + "/" + username + "/" + uuid+times + "." + entry.getKey());
ImgUrl.put(returnImage, (int) (entry.getValue().getSize()));
//ImgUrl.put(key.getRequestAddress() + "/" + username + "/" + uuid+times + "." + entry.getKey(), (int) (entry.getValue().getSize()/1024));
}else{
returnImage.setImgname(entry.getValue().getOriginalFilename());
returnImage.setImgurl("文件超出系统设定大小,不得超过");
ImgUrl.put(returnImage, -1);
}
}
return ImgUrl;