引入依赖
<!--aliyunOSS-->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
</dependency>
<!--图片压缩-->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
配置文件
package com.qqwl.gold.config;
import lombok.Data;
import java.io.Serializable;
/**
* @author zhongyuan
* @create 2020-11-12 18:49
*/
@Data
public class AliYunOssConfig implements Serializable {
//这里阿里云控制台 中的配置
private String endpoint = "http://oss-cn-shenzhen.aliyuncs.com";
private String AccessKey = "xxxxx";
private String AccessSecret = "xxxxx";
private String bucketName = "xxxxx";
private String fileHost = "xxxxx";
/**
* 访问路径
*/
private String webUrl = "xxxx";
// private String endpoint;
}
控制层
@PostMapping("/uploadVideo")
@ApiOperation("上传视频")
public Object uploadVideo(@RequestParam MultipartFile imgFile, HttpServletRequest req) throws Exception {
OSSUtil ossClient = new OSSUtil();
Map<String, Object> m = new HashMap<>();
if (imgFile.isEmpty()) {
m.put("error", "上传文件不能为空");
}
String newsUrl = "";
if (!((MultipartFile) imgFile).isEmpty()) {
try {
//将文件上传
String name = ossClient.uploadVideo(imgFile);
//