Browse Source

🎉 增加七牛上传demo

test
smallchill 6 years ago
parent
commit
1cee135b26
  1. 5
      blade-service/blade-desk/pom.xml
  2. 35
      blade-service/blade-desk/src/main/java/org/springblade/desk/controller/UploadController.java
  3. 7
      blade-service/blade-desk/src/main/resources/application-dev.yml

5
blade-service/blade-desk/pom.xml

@ -47,6 +47,11 @@
<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>
</dependencies>
<build>

35
blade-service/blade-desk/src/main/java/org/springblade/desk/controller/UploadController.java

@ -1,10 +1,17 @@
package org.springblade.desk.controller;
import com.qiniu.http.Response;
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.*;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.support.Kv;
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;
/**
@ -12,25 +19,43 @@ import org.springframework.web.multipart.MultipartFile;
*
* @author Chill
*/
@RequestMapping("/notice/upload")
@RestController
@AllArgsConstructor
@RequestMapping("/notice/upload")
public class UploadController {
private MinioTemplate minioTemplate;
private QiniuTemplate qiniuTemplate;
/**
* minio上传demo
*
* @param file 上传文件
* @param file 上传文件
* @param bucketName 存储桶名称
* @return String
*/
@SneakyThrows
@PostMapping("put-object")
public R<String> putObject(@RequestParam MultipartFile file, @RequestParam String bucketName) {
@PostMapping("put-minio-object")
public R<String> putMinioObject(@RequestParam MultipartFile file, @RequestParam String bucketName) {
minioTemplate.putObject(bucketName, file.getOriginalFilename(), file.getInputStream());
String objectUrl = minioTemplate.getObjectUrl(bucketName, file.getOriginalFilename());
return R.data(objectUrl);
}
/**
* qiniu上传demo
*
* @param file 上传文件
* @param fileKey 上传文件key
* @return String
*/
@SneakyThrows
@PostMapping("put-qiniu-object")
public R<Kv> putQiniuObject(@RequestParam MultipartFile file, @RequestParam String fileKey) {
Response put = qiniuTemplate.put(file.getInputStream(), fileKey);
Kv parse = JsonUtil.parse(put.bodyString(), Kv.class);
return R.data(parse);
}
}

7
blade-service/blade-desk/src/main/resources/application-dev.yml

@ -15,3 +15,10 @@ minio:
endpoint: http://127.0.0.1:9000
access-key: AZINRTAPCMMWMC9G7F3Z
secret-key: sHl2k4+vvmNaSZZdahUOHQwQDZGZl+4+ajRvBX8d
qiniu:
enable: true
endpoint: prv0t4ij6.bkt.clouddn.com
access-key: N_Loh1ngBqcJovwiAJqR91Ifj2vgOWHOf8AwBA_h
secret-key: AuzuA1KHAbkIndCU0dB3Zfii2O3crHNODDmpxHRS

Loading…
Cancel
Save