From 1927b989c55973e73529caf722569dce345a5784 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 26 May 2019 21:54:33 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=20=E5=A2=9E=E5=8A=A0oss=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blade-service/blade-demo/pom.xml | 10 ++++ .../demo/controller/UploadController.java | 59 +++++++++++++++++++ .../src/main/resources/application-dev.yml | 16 +++++ 3 files changed, 85 insertions(+) create mode 100644 blade-service/blade-demo/src/main/java/org/springblade/demo/controller/UploadController.java diff --git a/blade-service/blade-demo/pom.xml b/blade-service/blade-demo/pom.xml index bac353a6a..b6c14c68e 100644 --- a/blade-service/blade-demo/pom.xml +++ b/blade-service/blade-demo/pom.xml @@ -27,6 +27,16 @@ blade-starter-swagger ${bladex.tool.version} + + org.springblade + blade-starter-minio + ${bladex.tool.version} + + + org.springblade + blade-starter-qiniu + ${bladex.tool.version} + org.springblade blade-demo-api diff --git a/blade-service/blade-demo/src/main/java/org/springblade/demo/controller/UploadController.java b/blade-service/blade-demo/src/main/java/org/springblade/demo/controller/UploadController.java new file mode 100644 index 000000000..9c2c69c67 --- /dev/null +++ b/blade-service/blade-demo/src/main/java/org/springblade/demo/controller/UploadController.java @@ -0,0 +1,59 @@ +package org.springblade.demo.controller; + +import lombok.AllArgsConstructor; +import lombok.SneakyThrows; +import org.springblade.core.minio.MinioTemplate; +import org.springblade.core.qiniu.QiniuTemplate; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.util.Objects; + +/** + * UploadController + * + * @author Chill + */ +@RestController +@AllArgsConstructor +@RequestMapping("/notice/upload") +public class UploadController { + + private MinioTemplate minioTemplate; + + private QiniuTemplate qiniuTemplate; + + /** + * minio上传demo + * + * @param file 上传文件 + * @return String + */ + @SneakyThrows + @PostMapping("put-minio-object") + public R putMinioObject(@RequestParam MultipartFile file) { + minioTemplate.putFile(file); + String link = minioTemplate.fileLink(Objects.requireNonNull(file.getOriginalFilename())); + return R.data(link); + } + + /** + * qiniu上传demo + * + * @param file 上传文件 + * @param fileKey 上传文件key + * @return String + */ + @SneakyThrows + @PostMapping("put-qiniu-object") + public R putQiniuObject(@RequestParam MultipartFile file, @RequestParam String fileKey) { + qiniuTemplate.putFile(fileKey,file); + String link = qiniuTemplate.fileLink(fileKey); + return R.data(link); + } + +} diff --git a/blade-service/blade-demo/src/main/resources/application-dev.yml b/blade-service/blade-demo/src/main/resources/application-dev.yml index 25056f70f..5fcbd2711 100644 --- a/blade-service/blade-demo/src/main/resources/application-dev.yml +++ b/blade-service/blade-demo/src/main/resources/application-dev.yml @@ -8,3 +8,19 @@ spring: url: ${blade.datasource.dev.url} username: ${blade.datasource.dev.username} password: ${blade.datasource.dev.password} + +minio: + enable: true + tenant-mode: false + endpoint: http://127.0.0.1:9000 + access-key: D99KGE6ZTQXSATTJWU24 + secret-key: QyVqGnhIQQE734UYSUFlGOZViE6+ZlDEfUG3NjhJ + bucket-name: bladex + +qiniu: + enable: true + tenant-mode: false + endpoint: prv0t4ij6.bkt.clouddn.com + access-key: N_Loh1ngBqcJovwiAJqR91Ifj2vgOWHOf8AwBA_h + secret-key: AuzuA1KHAbkIndCU0dB3Zfii2O3crHNODDmpxHRS + bucket-name: bladex