february-file/february-file-server/src/main/java/com/february/file/service/LocalSysFileServiceImpl.java

51 lines
1.1 KiB
Java

package com.february.file.service;
import com.february.file.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
* 本地文件存储
*
* @author february
*/
@Primary
@Service
public class LocalSysFileServiceImpl implements ISysFileService
{
/**
* 资源映射路径 前缀
*/
@Value("/statics")
public String localFilePrefix;
/**
* 域名或本机访问地址
*/
@Value("http://10.100.1.2:9300")
public String domain;
/**
* 上传文件存储在本地的根路径
*/
@Value("D:/February/uploadPath")
private String localFilePath;
/**
* 本地文件上传接口
*
* @param file 上传的文件
* @return 访问地址
* @throws Exception
*/
@Override
public String uploadFile(MultipartFile file) throws Exception
{
String name = FileUploadUtils.upload(localFilePath, file);
String url = domain + localFilePrefix + name;
return url;
}
}