parent
ee986521e1
commit
6addca7e50
@ -1,17 +1,16 @@
|
||||
package com.sky.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "sky.alioss")
|
||||
@ConfigurationProperties(prefix = "aliyun.oss")
|
||||
@Data
|
||||
public class AliOssProperties {
|
||||
|
||||
private String endpoint;
|
||||
private String accessKeyId;
|
||||
private String accessKeySecret;
|
||||
private String bucketName;
|
||||
|
||||
private String region;
|
||||
}
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
|
||||
import com.sky.result.Result;
|
||||
import com.sky.utils.AliOssUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/admin/common")
|
||||
public class UploadController {
|
||||
@Autowired
|
||||
private AliOssUtil aliOssUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
public Result<String> upload(MultipartFile file) throws Exception {
|
||||
log.info("文件上传:{}",file);
|
||||
|
||||
//将文件交给阿里云OSS存储管理
|
||||
String url = aliOssUtil.upload(file.getBytes(), file.getOriginalFilename());
|
||||
log.info("文件上传完成,返回访问链接:{}",url);
|
||||
return Result.success(url);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue