RuoYi
4 years ago
6 changed files with 132 additions and 20 deletions
@ -0,0 +1,43 @@ |
|||||||
|
package com.ruoyi.file.service; |
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
import com.github.tobato.fastdfs.domain.fdfs.StorePath; |
||||||
|
import com.github.tobato.fastdfs.service.FastFileStorageClient; |
||||||
|
|
||||||
|
/** |
||||||
|
* FastDFS文件存储 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class FastDfsSysFileServiceImpl implements ISysFileService |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 域名或本机访问地址 |
||||||
|
*/ |
||||||
|
@Value("${fdfs.domain}") |
||||||
|
public String domain; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private FastFileStorageClient storageClient; |
||||||
|
|
||||||
|
/** |
||||||
|
* FastDfs文件上传接口 |
||||||
|
* |
||||||
|
* @param file 上传的文件 |
||||||
|
* @param baseDir 相对应用的基目录 |
||||||
|
* @return 访问地址 |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public String uploadFile(MultipartFile file, String baseDir) throws Exception |
||||||
|
{ |
||||||
|
StorePath storePath = storageClient.uploadFile(file.getInputStream(), file.getSize(), |
||||||
|
FilenameUtils.getExtension(file.getOriginalFilename()), null); |
||||||
|
return domain + "/" + storePath.getFullPath(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue