文件上传 moni

pull/64/head
陈云志 5 years ago
parent 6f8823b373
commit d0e85a00f8

@ -1,12 +1,13 @@
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
@ -14,8 +15,8 @@ import com.github.tobato.fastdfs.service.FastFileStorageClient;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
public class FastDfsSysFileServiceImpl implements ISysFileService @ConfigurationProperties(prefix = "fdfs")
{ public class FastDfsSysFileServiceImpl implements ISysFileService {
/** /**
* 访 * 访
*/ */
@ -33,8 +34,7 @@ public class FastDfsSysFileServiceImpl implements ISysFileService
* @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 com.ruoyi.file.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Value; 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 org.springframework.web.multipart.MultipartFile;
import com.ruoyi.file.utils.FileUploadUtils;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@Primary
@Service //@Service
public class LocalSysFileServiceImpl implements ISysFileService //@ConfigurationProperties(prefix = "fdfs")
{ public class LocalSysFileServiceImpl implements ISysFileService {
/** /**
* *
*/ */
@ -40,8 +38,8 @@ public class LocalSysFileServiceImpl implements ISysFileService
* @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,12 +1,13 @@
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
@ -14,8 +15,8 @@ import io.minio.PutObjectArgs;
* @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;
@ -29,8 +30,8 @@ public class MinioSysFileServiceImpl implements ISysFileService
* @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…
Cancel
Save