From 1a4792fdff667d3b9590c6ab4c085a08cdca1399 Mon Sep 17 00:00:00 2001
From: zrj <646384940@qq.com>
Date: Thu, 24 Oct 2024 14:07:18 +0800
Subject: [PATCH] 修改端口

---
 src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java |   71 +++++++++++++++++++++++++++++++++--
 1 files changed, 66 insertions(+), 5 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 99196f9..a5928ea 100644
--- a/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
+++ b/src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -156,7 +156,22 @@
 	@PostMapping("/put-file")
 	public R<BladeFile> putFile(@RequestParam MultipartFile file) {
 		BladeFile bladeFile = ossBuilder.template().putFile(file.getOriginalFilename(), file.getInputStream());
+		changeLink(bladeFile);
 		return R.data(bladeFile);
+	}
+
+
+	/**
+	 * 修改link
+	 *
+	 * @param bladeFile
+	 */
+	private void changeLink(BladeFile bladeFile) {
+		if (null != bladeFile) {
+			// 替换url link 前缀
+			String newLink = ossBuilder.ossProperties().getEndpoint() + bladeFile.getName();
+			bladeFile.setLink(newLink);
+		}
 	}
 
 	/**
@@ -262,10 +277,10 @@
 	@PostMapping("put-files-talk")
 	public String putFilestak(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
 		//填写你文件上传的地址以及相应信息
-		String url = "http://223.82.109.183:2081";
-		String access = "zhbaadmin";
-		String secret = "zhbapassword";
-		String bucket = "zhxy";
+		String url = "http://web.byisf.com:9000";
+		String access = "adminminio";
+		String secret = "adminminio";
+		String bucket = "jfpt";
 		MinioClient minioClient =
 			MinioClient.builder()
 				.endpoint(url)
@@ -295,7 +310,53 @@
 				.build());
 
 		//文件推送
-		String urls = "http://223.82.109.183:2081/zhxy/"+newName;
+		String urls = "http://web.byisf.com:9000/jfpt/"+newName;
+		//返回
+		return urls;
+	}
+
+	/**
+	 * 文件上传,个人头像上传
+	 *
+	 * @param file 图片对象
+	 */
+	@GetMapping("put-files-talks")
+	public String putFilestaks(@RequestParam MultipartFile file) throws IOException, ServerException, InsufficientDataException, InternalException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, XmlParserException, ErrorResponseException {
+		//填写你文件上传的地址以及相应信息
+		String url = "http://web.byisf.com:9000";
+		String access = "adminminio";
+		String secret = "adminminio";
+		String bucket = "jfpt";
+		MinioClient minioClient =
+			MinioClient.builder()
+				.endpoint(url)
+				.credentials(access, secret)
+				.build();
+		// 检查存储桶是否已经存在
+		boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build());
+		if (!isExist) {
+			// 创建一个名为zip的存储桶,用于zip文件。
+			minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
+			minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).build());
+		}
+		String fileName = file.getOriginalFilename();
+		String newName = "upload/picture/" + UUID.randomUUID().toString().replaceAll("-", "")
+			+ fileName.substring(fileName.lastIndexOf("."));
+		InputStream in = file.getInputStream();
+		String[] split = newName.split("/");
+		//创建头部信息
+		Map<String, String> headers = new HashMap<>(1 << 2);
+		//添加自定义内容类型
+		headers.put("Content-Type", "application/octet-stream");
+		//上传
+		minioClient.putObject(
+			PutObjectArgs.builder().bucket(bucket).object(newName).stream(
+				in, in.available(), -1)
+				.headers(headers)
+				.build());
+
+		//文件推送
+		String urls = "http://web.byisf.com:9000/jfpt/"+newName;
 		//返回
 		return urls;
 	}

--
Gitblit v1.9.3