From 9575aee99a9beccba3a66273b9ee45ad706d3f42 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Tue, 20 Feb 2024 17:19:58 +0800
Subject: [PATCH] 新增文件上传接口(可以根据前缀进行上传)

---
 src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java b/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
index 473107a..4f1b37e 100644
--- a/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
+++ b/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -206,7 +206,7 @@
 	 */
 	@SneakyThrows
 	@PostMapping("/put-file-attach-by-name")
-	public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file) {
+	public R<BladeFile> putFileAttach(@RequestParam(required = false) String fileName, @RequestParam MultipartFile file) {
 		BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
 		Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
 		bladeFile.setAttachId(attachId);
@@ -214,6 +214,41 @@
 	}
 
 	/**
+	 * 自定义前缀上传文件
+	 *
+	 * @param file 文件
+	 * @param prefixPath 文件
+	 * @return ObjectStat
+	 */
+	@SneakyThrows
+	@PostMapping("/put-file-by-prefix-path")
+	public R<BladeFile> putFileByPrefixPath(@RequestParam MultipartFile file,@RequestParam(required = false) String prefixPath) {
+		BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream());
+		// 修改link
+		changeLink(bladeFile);
+		return R.data(bladeFile);
+	}
+
+	/**
+	 * 自定义前缀上传文件并保存至附件表
+	 *
+	 * @param file 文件
+	 * @param prefixPath 文件
+	 * @return ObjectStat
+	 */
+	@SneakyThrows
+	@PostMapping("/put-file-attach-by-prefix-path")
+	public R<BladeFile> putFileAttachByPrefixPath(@RequestParam MultipartFile file,@RequestParam(required = false) String prefixPath) {
+		String fileName = file.getOriginalFilename();
+		BladeFile bladeFile = ossBuilder.templateByPrefixPath(prefixPath).putFile(file.getOriginalFilename(), file.getInputStream());
+		Long attachId = buildAttach(fileName, file.getSize(), bladeFile);
+		bladeFile.setAttachId(attachId);
+		// 修改link
+		changeLink(bladeFile);
+		return R.data(bladeFile);
+	}
+
+	/**
 	 * 构建附件表
 	 *
 	 * @param fileName  文件名

--
Gitblit v1.9.3