Browse Source

🎉 优化oss上传demo

test
smallchill 6 years ago
parent
commit
34c2e2a36f
  1. 15
      blade-service/blade-desk/src/main/java/org/springblade/desk/controller/UploadController.java
  2. 7
      blade-service/blade-desk/src/main/resources/application-dev.yml

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

@ -14,6 +14,8 @@ 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
*
@ -31,16 +33,15 @@ public class UploadController {
/**
* minio上传demo
*
* @param file 上传文件
* @param bucketName 存储桶名称
* @param file 上传文件
* @return String
*/
@SneakyThrows
@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);
public R<String> putMinioObject(@RequestParam MultipartFile file) {
minioTemplate.putObject(file);
String objectLink = minioTemplate.getObjectLink(Objects.requireNonNull(file.getOriginalFilename()));
return R.data(objectLink);
}
/**
@ -53,7 +54,7 @@ public class UploadController {
@SneakyThrows
@PostMapping("put-qiniu-object")
public R<Kv> putQiniuObject(@RequestParam MultipartFile file, @RequestParam String fileKey) {
Response put = qiniuTemplate.put(file.getInputStream(), fileKey);
Response put = qiniuTemplate.putObject(file, fileKey);
Kv parse = JsonUtil.parse(put.bodyString(), Kv.class);
return R.data(parse);
}

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

@ -13,12 +13,15 @@ minio:
enable: true
tenant-mode: false
endpoint: http://127.0.0.1:9000
access-key: AZINRTAPCMMWMC9G7F3Z
secret-key: sHl2k4+vvmNaSZZdahUOHQwQDZGZl+4+ajRvBX8d
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