mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-10 06:09:12 +00:00
fix 修复 dubbo 传输文件问题 临时更改 后续对接oss
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.ruoyi.file.api;
|
||||
|
||||
import com.ruoyi.file.api.domain.SysFile;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 文件服务
|
||||
@@ -16,5 +15,5 @@ public interface RemoteFileService {
|
||||
* @param file 文件信息
|
||||
* @return 结果
|
||||
*/
|
||||
SysFile upload(MultipartFile file);
|
||||
SysFile upload(String name, String originalFilename, String contentType, byte[] file);
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 文件信息
|
||||
*
|
||||
@@ -12,7 +14,10 @@ import lombok.experimental.Accessors;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class SysFile {
|
||||
public class SysFile implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@@ -113,7 +113,7 @@ public class SysProfileController extends BaseController {
|
||||
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
|
||||
if (!file.isEmpty()) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
SysFile sysFile = remoteFileService.upload(file);
|
||||
SysFile sysFile = remoteFileService.upload(file.getName(), file.getOriginalFilename(), file.getContentType(), file.getBytes());
|
||||
if (StringUtils.isNull(sysFile)) {
|
||||
return AjaxResult.error("文件服务异常,请联系管理员");
|
||||
}
|
||||
|
Reference in New Issue
Block a user