本文主要介绍了Java架构师技术中关于kkfileviewer的安装、配置和使用方法,以及Springboot集成minio的过程和测试方法。同时介绍了ChatGPT在国内的使用推荐和一个知识星球社群的介绍及福利。
包括在pom.xml中添加依赖、配置minio文件存储信息、配置minio的类和方法以及minio工具类的编写。
介绍了星球能给大家提供的内容、福利和加入星球后的优势。
以下文章来源Java架构师技术,回复”Spring“获惊喜礼包
来源:小太阳 链接:juejin.cn/post/7407384172049891379
大家好,我是Java架构师
1、容器安装kkfileviewer
1.1 下载文件
这里以kkfile 4.4.0-beta版本为例
下载kkfile安装包及Dockerfile:
https://codeup.aliyun.com/6254dee9a923b68581caaf50/kkfileviewer.git
1.2、构建镜像
git clone https://codeup.aliyun.com/6254dee9a923b68581caaf50/kkfileviewer.git
cd kkfileviewer
docker build -t kkfileview:v4.4.0 .
1.3、 启动kkfileviewer
docker run -d -p 8012:8012 --name kkfileview kkfileview:v4.4.0
1.4、 访问测试
http://you-ip:8012
2、springboot集成minio
2.1 pom.xml添加依赖
<dependency>
<groupId>io.miniogroupId>
<artifactId>minioartifactId>
<version>8.5.11version>
dependency>
2.2、 配置
# minio 文件存储配置信息
minio:
endpoint: http://xxxxx:9000
accessKey: xxxx
secretKey: xxxxx
bucketName: test
2.3、minio配置类
package com.sunny.config;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MinioConfig {
@Value("${minio.endpoint}")
private String endPoint;
@Value("${minio.accessKey}")
private String accessKey;
@Value("${minio.secretKey}")
private String secretKey;
@Value("${minio.bucketName}")
private String bucketName;
@Bean
protected MinioClient minioClient(){
return MinioClient.builder()
.endpoint(endPoint)
.credentials(accessKey, secretKey)
.build();
}
}
2.4、 minio工具类
package com.sunny.utils;
import com.sunny.entity.common.ApiResult;
import com.sunny.exception.AppException;
import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.http.Method;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
@Component
public class MinioUtils {
@Value("${minio.bucketName}")
private String bucketName;
@Resource
private MinioClient minioClient;
public ApiResult uploadFile(MultipartFile file) throws AppException {
String fileName = System.currentTimeMillis() + file.getOriginalFilename();
try (InputStream fi = file.getInputStream()) {
PutObjectArgs putObjectArgs = PutObjectArgs.builder().bucket(bucketName).contentType(file.getContentType()).object(fileName).stream(fi, fi.available(), -1).build();
minioClient.putObject(putObjectArgs);
} catch (Exception e) {
throw new AppException("文件上传失败" + e.getMessage());
}
return ApiResult.ok(fileName);
}
public ApiResult getPreviewUrl(String objectName) throws AppException {
try {
GetPresignedObjectUrlArgs urlArgs = GetPresignedObjectUrlArgs.builder().bucket(bucketName).object(objectName).method(Method.GET).build();
return ApiResult.ok(minioClient.getPresignedObjectUrl(urlArgs));
} catch (Exception e) {
throw new AppException("获取预览链接失败" + e.getMessage());
}
}
}
2.5、接口
package com.sunny.controller;
import com.sunny.entity.common.ApiResult;
import com.sunny.exception.AppException;
import com.sunny.utils.MinioUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/file")
public class FileOperationController {
@Resource
private MinioUtils minioUtils;
@PostMapping("/upload")
public ApiResult upload(MultipartFile file) throws AppException {
return minioUtils.uploadFile(file);
}
@GetMapping("/getPreviewUrl")
public ApiResult getPreviewUrl(String fileName) throws AppException {
return minioUtils.getPreviewUrl(fileName);
}
}
3、测试
3.1、上传文件
3.2、获取minio文件预览地址
3.1中返回一个文件名,该文件名为上传文件在minio中的唯一名称,使用该名称请求minio文件预览地址
3.3、文件预览
3.2中的接口返回一个地址,将地址放到kkfileviewer文件预览服务中,可以预览文件
上周,又劝退十几个了。。。
ChatGPT 4.0 国内直接用 !!!
最后给大家推荐一个ChatGPT 4.0国内网站,是我们团队一直在使用的,我们对接是OpenAI官网的账号,给大家打造了一个一模一样ChatGPT,很多粉丝朋友现在也都通过我拿这种号,价格不贵,关键还有售后。
一句话说明:用官方一半价格的钱,一句话说明:用跟官方 ChatGPT4.0 一模一样功能,无需魔法,无视封号,不必担心次数不够。
最大优势:可实现会话隔离!突破限制:官方限制每个账号三小时可使用40次4.0本网站可实现次数上限之后,手动切换下一个未使用的账号【相当于一个4.0帐号,同享受一百个账号轮换使用权限】
为了跟上AI时代我干了一件事儿,我创建了一个知识星球社群:AI俱乐部与副业。想带着大家一起探索ChatGPT和新的AI时代。
有很多小伙伴搞不定ChatGPT账号,于是我们决定,凡是这三天之内加入ChatPGT的小伙伴,我们直接送一个正常可用的永久ChatGPT独立账户。
不光是增长速度最快,我们的星球品质也绝对经得起考验,短短一个月时间,我们的课程团队发布了8个专栏、18个副业项目:
简单说下这个星球能给大家提供什么:
1、不断分享如何使用ChatGPT来完成各种任务,让你更高效地使用ChatGPT,以及副业思考、变现思路、创业案例、落地案例分享。
2、分享ChatGPT的使用方法、最新资讯、商业价值。
3、探讨未来关于ChatGPT的机遇,共同成长。
4、帮助大家解决ChatGPT遇到的问题。
5、提供一整年的售后服务,一起搞副业
星球福利:
1、加入星球4天后,就送ChatGPT独立账号。
2、邀请你加入ChatGPT会员交流群。
3、赠送一份完整的ChatGPT手册和66个ChatGPT副业赚钱手册。
4、赠送一个月的ChatGPT 4.0 Plus系统池账号,价值98元。
5、赠送一份总价值5000元的ChatGPT视频教程。
其它福利还在筹划中... 不过,我给你大家保证,加入星球后,收获的价值会远远大于今天加入的门票费用 !
本星球第二期原价399,目前有优惠券,早鸟价159,每超过50人涨价10元,星球马上要来一波大的涨价,如果你还在犹豫,可能最后就要以更高价格加入了。。
早就是优势。建议大家尽早以便宜的价格加入!
最后,整理了300多套项目,赠送读者。扫码下方二维码,后台回复【赚钱】即可获取。
--END--
来源:波波烤鸭
链接:dpb-bobokaoya-sm.blog.csdn.net/artiacle/details/103409430
版权申明:内容来源网络,版权归原创者所有。除非无法确认,我们都会标明作者及出处,如有侵权烦请告知,我们会立即删除并表示歉意。谢谢!