fix 修复 dubbo 传输文件问题 临时更改 后续对接oss

This commit is contained in:
疯狂的狮子li
2022-01-18 10:15:06 +08:00
parent 337ef9761b
commit 4b5d0fac02
4 changed files with 197 additions and 138 deletions

View File

@@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
/**
* 文件请求处理
*
@@ -28,10 +30,11 @@ public class RemoteFileServiceImpl implements RemoteFileService {
* 文件上传请求
*/
@Override
public SysFile upload(MultipartFile file) {
public SysFile upload(String name, String originalFilename, String contentType, byte[] file) {
MultipartFile multipartFile = getMultipartFile(name, originalFilename, contentType, file);
try {
// 上传并返回访问地址
String url = sysFileService.uploadFile(file);
String url = sysFileService.uploadFile(multipartFile);
SysFile sysFile = new SysFile();
sysFile.setName(FileUtils.getName(url));
sysFile.setUrl(url);
@@ -41,4 +44,56 @@ public class RemoteFileServiceImpl implements RemoteFileService {
throw new ServiceException("上传文件失败");
}
}
}
private MultipartFile getMultipartFile(String name, String originalFilename, String contentType, byte[] file) {
return new MultipartFile() {
@Override
public String getName() {
return name;
}
@Override
public String getOriginalFilename() {
return originalFilename;
}
@Override
public String getContentType() {
return contentType;
}
@Override
public boolean isEmpty() {
return getSize() == 0;
}
@Override
public long getSize() {
return file.length;
}
@Override
public byte[] getBytes() throws IOException {
return file;
}
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(file);
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(dest);
outputStream.write(file);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
};
}
}