Browse Source

🎉 增加oss demo

test
smallchill 6 years ago
parent
commit
1927b989c5
  1. 10
      blade-service/blade-demo/pom.xml
  2. 59
      blade-service/blade-demo/src/main/java/org/springblade/demo/controller/UploadController.java
  3. 16
      blade-service/blade-demo/src/main/resources/application-dev.yml

10
blade-service/blade-demo/pom.xml

@ -27,6 +27,16 @@
<artifactId>blade-starter-swagger</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-minio</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-qiniu</artifactId>
<version>${bladex.tool.version}</version>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-demo-api</artifactId>

59
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<String> 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<String> putQiniuObject(@RequestParam MultipartFile file, @RequestParam String fileKey) {
qiniuTemplate.putFile(fileKey,file);
String link = qiniuTemplate.fileLink(fileKey);
return R.data(link);
}
}

16
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

Loading…
Cancel
Save