update 上传阿里云oss

This commit is contained in:
2023-04-04 16:36:19 +08:00
parent 218c5715ac
commit 5acf8489cd
5 changed files with 193 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import com.jsowell.common.config.JsowellConfig;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.file.AliyunOssUploadUtils;
import com.jsowell.common.util.file.FileUploadUtils;
import com.jsowell.common.util.file.FileUtils;
import com.jsowell.framework.config.ServerConfig;
@@ -11,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -160,4 +162,21 @@ public class CommonController {
return AjaxResult.error(e.getMessage());
}
}
@CrossOrigin
@PostMapping("/uploadOSS")
public AjaxResult uploadFileOSS(MultipartFile file) throws Exception {
System.out.println(file);
try {
String url = AliyunOssUploadUtils.uploadFile(file);
AjaxResult ajax = AjaxResult.success();
ajax.put("url", url);
ajax.put("fileName", FileUtils.getName(url));
ajax.put("newFileName", FileUtils.getName(url));
ajax.put("originalFilename", file.getOriginalFilename());
return ajax;
}catch (Exception e){
return AjaxResult.error(e.getMessage());
}
}
}

View File

@@ -104,6 +104,20 @@ minio:
secretKey: minioadmin
bucketName: jsowell
aliyunoss:
# 地域节点
endpoint: oss-cn-shanghai.aliyuncs.com
# AccessKey
accessKeyId: LTAI5tBgCN4xuxQF1HV9rf7t
# AccessKey 秘钥
accessKeySecret: tsxMyujk6KY9h0e4Bx0D7ld16PBUyW
# bucket名称
bucketName: ydc-oss-dev
# bucket下文件夹的路径
filehost: img
# 访问域名
url: ydc-oss-dev.oss-cn-shanghai.aliyuncs.com
########################微信支付参数#######################################
#微信商户号