文件上传 moni
This commit is contained in:
parent
6f8823b373
commit
d0e85a00f8
|
|
@ -1,21 +1,22 @@
|
||||||
package com.ruoyi.file.service;
|
package com.ruoyi.file.service;
|
||||||
|
|
||||||
|
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
||||||
|
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
|
|
||||||
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FastDFS 文件存储
|
* FastDFS 文件存储
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class FastDfsSysFileServiceImpl implements ISysFileService
|
@ConfigurationProperties(prefix = "fdfs")
|
||||||
{
|
public class FastDfsSysFileServiceImpl implements ISysFileService {
|
||||||
/**
|
/**
|
||||||
* 域名或本机访问地址
|
* 域名或本机访问地址
|
||||||
*/
|
*/
|
||||||
|
|
@ -27,14 +28,13 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FastDfs文件上传接口
|
* FastDfs文件上传接口
|
||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @return 访问地址
|
* @return 访问地址
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
public String uploadFile(MultipartFile file) throws Exception {
|
||||||
{
|
|
||||||
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
|
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(),
|
||||||
FilenameUtils.getExtension(file.getOriginalFilename()), null);
|
FilenameUtils.getExtension(file.getOriginalFilename()), null);
|
||||||
return domain + "/" + storePath.getFullPath();
|
return domain + "/" + storePath.getFullPath();
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
package com.ruoyi.file.service;
|
package com.ruoyi.file.service;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import com.ruoyi.file.utils.FileUploadUtils;
|
import com.ruoyi.file.utils.FileUploadUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地文件存储
|
* 本地文件存储
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Primary
|
|
||||||
@Service
|
//@Service
|
||||||
public class LocalSysFileServiceImpl implements ISysFileService
|
//@ConfigurationProperties(prefix = "fdfs")
|
||||||
{
|
public class LocalSysFileServiceImpl implements ISysFileService {
|
||||||
/**
|
/**
|
||||||
* 资源映射路径 前缀
|
* 资源映射路径 前缀
|
||||||
*/
|
*/
|
||||||
|
|
@ -26,7 +24,7 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
*/
|
*/
|
||||||
@Value("${file.domain}")
|
@Value("${file.domain}")
|
||||||
public String domain;
|
public String domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件存储在本地的根路径
|
* 上传文件存储在本地的根路径
|
||||||
*/
|
*/
|
||||||
|
|
@ -35,13 +33,13 @@ public class LocalSysFileServiceImpl implements ISysFileService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地文件上传接口
|
* 本地文件上传接口
|
||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @return 访问地址
|
* @return 访问地址
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
@Override
|
||||||
{
|
public String uploadFile(MultipartFile file) throws Exception {
|
||||||
String name = FileUploadUtils.upload(localFilePath, file);
|
String name = FileUploadUtils.upload(localFilePath, file);
|
||||||
String url = domain + localFilePrefix + name;
|
String url = domain + localFilePrefix + name;
|
||||||
return url;
|
return url;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
package com.ruoyi.file.service;
|
package com.ruoyi.file.service;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import com.ruoyi.file.config.MinioConfig;
|
import com.ruoyi.file.config.MinioConfig;
|
||||||
import com.ruoyi.file.utils.FileUploadUtils;
|
import com.ruoyi.file.utils.FileUploadUtils;
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
import io.minio.PutObjectArgs;
|
import io.minio.PutObjectArgs;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minio 文件存储
|
* Minio 文件存储
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class MinioSysFileServiceImpl implements ISysFileService
|
@Primary
|
||||||
{
|
public class MinioSysFileServiceImpl implements ISysFileService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private MinioConfig minioConfig;
|
private MinioConfig minioConfig;
|
||||||
|
|
||||||
|
|
@ -24,13 +25,13 @@ public class MinioSysFileServiceImpl implements ISysFileService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地文件上传接口
|
* 本地文件上传接口
|
||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
* @return 访问地址
|
* @return 访问地址
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public String uploadFile(MultipartFile file) throws Exception
|
@Override
|
||||||
{
|
public String uploadFile(MultipartFile file) throws Exception {
|
||||||
String fileName = FileUploadUtils.extractFilename(file);
|
String fileName = FileUploadUtils.extractFilename(file);
|
||||||
PutObjectArgs args = PutObjectArgs.builder()
|
PutObjectArgs args = PutObjectArgs.builder()
|
||||||
.bucket(minioConfig.getBucketName())
|
.bucket(minioConfig.getBucketName())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue