'123'
This commit is contained in:
parent
ec396a9437
commit
2bce229a7b
|
@ -168,7 +168,7 @@ public class CommonController
|
|||
* Minio 服务器上传请求(单文件上传)
|
||||
*/
|
||||
@PostMapping("/minio-upload")
|
||||
public AjaxResult uploadFileMinio(MultipartFile file) throws Exception
|
||||
public AjaxResult uploadFileMinio(String dir,MultipartFile file) throws Exception
|
||||
{
|
||||
if(file == null){
|
||||
return AjaxResult.error("不能上传空文件");
|
||||
|
@ -176,7 +176,7 @@ public class CommonController
|
|||
try
|
||||
{
|
||||
// 上传并返回新文件名称
|
||||
String fileName = FileUploadUtils.uploadMinio(file);
|
||||
String fileName = FileUploadUtils.uploadMinio(dir,file);
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("url", fileName);
|
||||
ajax.put("fileName", fileName);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -36,6 +37,9 @@ import java.util.regex.Pattern;
|
|||
@RequestMapping("/system/user/profile")
|
||||
public class SysProfileController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
|
@ -132,7 +136,8 @@ public class SysProfileController extends BaseController
|
|||
if (!file.isEmpty())
|
||||
{
|
||||
LoginUser loginUser = getLoginUser();
|
||||
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
|
||||
//String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
|
||||
String avatar = FileUploadUtils.uploadMinio("user",file);
|
||||
if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
||||
{
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
|
|
|
@ -201,10 +201,10 @@ magic-api:
|
|||
# Minio配置-分布式存储
|
||||
minio:
|
||||
useEnable: true
|
||||
url: http://localhost:3336
|
||||
url: http://192.168.9.134:3336
|
||||
accessKey: minio-admin
|
||||
secretKey: minio-jndlitzx
|
||||
bucketName: jndl
|
||||
bucketName: system
|
||||
|
||||
# OA单点登录key
|
||||
OA:
|
||||
|
|
|
@ -129,15 +129,16 @@ public class FileUploadUtils
|
|||
/**
|
||||
* 以默认BucketName配置上传到Minio服务器
|
||||
*
|
||||
* @param dir 分类目录
|
||||
* @param file 上传的文件
|
||||
* @return 文件名称
|
||||
* @throws IOException 写入异常
|
||||
*/
|
||||
public static String uploadMinio(MultipartFile file) throws IOException
|
||||
public static String uploadMinio(String dir,MultipartFile file) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return uploadMinio(getBucketName(), file);
|
||||
return uploadMinio(getBucketName(),dir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -152,11 +153,11 @@ public class FileUploadUtils
|
|||
* @return 文件名称
|
||||
* @throws IOException 写入异常
|
||||
*/
|
||||
public static String uploadMinio(MultipartFile file, String bucketName) throws IOException
|
||||
public static String uploadMinio(MultipartFile file, String bucketName,String dir) throws IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
return uploadMinio(bucketName, file);
|
||||
return uploadMinio(bucketName,dir, file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -164,18 +165,18 @@ public class FileUploadUtils
|
|||
}
|
||||
}
|
||||
|
||||
private static String uploadMinio(String bucketName, MultipartFile file) throws Exception
|
||||
private static String uploadMinio(String bucketName, String dir, MultipartFile file, String[] allowedExtension) throws Exception
|
||||
{
|
||||
int fileNameLength = file.getOriginalFilename().length();
|
||||
if (fileNameLength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH)
|
||||
{
|
||||
throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
|
||||
}
|
||||
assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
|
||||
assertAllowed(file, allowedExtension);
|
||||
try
|
||||
{
|
||||
String fileName = extractFilename(file);
|
||||
return MinioUtil.uploadFile(bucketName, fileName, file);
|
||||
return MinioUtil.uploadFile(bucketName,dir, fileName, file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.ruoyi.common.utils.file;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -40,17 +37,21 @@ public class MinioUtil
|
|||
* 上传文件
|
||||
*
|
||||
* @param bucketName 桶名称
|
||||
* @param dir 分类目录
|
||||
* @param fileName 文件名
|
||||
* @throws IOException 写入异常
|
||||
*/
|
||||
public static String uploadFile(String bucketName, String fileName, MultipartFile multipartFile) throws IOException
|
||||
public static String uploadFile(String bucketName,String dir, String fileName, MultipartFile multipartFile) throws IOException
|
||||
{
|
||||
|
||||
String url = "";
|
||||
try (InputStream inputStream = multipartFile.getInputStream())
|
||||
{
|
||||
MINIO_CLIENT.putObject(PutObjectArgs.builder().bucket(bucketName).object(fileName).stream(inputStream, multipartFile.getSize(), -1).contentType(multipartFile.getContentType()).build());
|
||||
String url = MINIO_CLIENT.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().bucket(bucketName).object(fileName).method(Method.GET).build());
|
||||
boolean exist = existBucket(bucketName);
|
||||
if(exist){
|
||||
MINIO_CLIENT.putObject(PutObjectArgs.builder().bucket(bucketName).object(dir+"/"+fileName).stream(inputStream, multipartFile.getSize(), -1).contentType(multipartFile.getContentType()).build());
|
||||
url = MINIO_CLIENT.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().bucket(bucketName).object(dir+"/"+fileName).method(Method.GET).build());
|
||||
url = url.substring(0, url.indexOf('?'));
|
||||
}
|
||||
return ServletUtils.urlDecode(url);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -71,7 +71,8 @@ const user = {
|
|||
return new Promise((resolve, reject) => {
|
||||
getInfo().then(res => {
|
||||
const user = res.user
|
||||
const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar;
|
||||
//const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar;
|
||||
const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/profile.jpg") : user.avatar;
|
||||
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
|
||||
commit('SET_ROLES', res.roles)
|
||||
commit('SET_PERMISSIONS', res.permissions)
|
||||
|
|
|
@ -137,7 +137,8 @@ export default {
|
|||
formData.append("avatarfile", data, this.options.filename);
|
||||
uploadAvatar(formData).then(response => {
|
||||
this.open = false;
|
||||
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
|
||||
//this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
|
||||
this.options.img = response.imgUrl;
|
||||
store.commit('SET_AVATAR', this.options.img);
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.visible = false;
|
||||
|
|
Loading…
Reference in New Issue