数据集下载到另一个服务器

master
whb
parent 1b6e200356
commit 06485762bf

@ -12,8 +12,10 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@ -276,6 +278,29 @@ public class JupyterController {
@PostMapping("uploadFile")
@ApiOperation("新增数据集") //todo 案例目录和案例正文通过前端传路径过来 这里只存url
@AnonymousAccess
ResultEntity<String> uploadFile(List<MultipartFile> dataFile) {
String filepath = "/usr/local/tianzeProject/financial_bigdata_total/py/dataResource/";
//设置数据文件
if (dataFile != null && !dataFile.isEmpty()) {
for (MultipartFile file : dataFile) {
iFileUtil.uploadResource(file,filepath);
}
}
return new ResultEntity<>(HttpStatus.OK,"上传成功");
}

@ -88,4 +88,5 @@ public interface IFileUtil {
void downloadByOtherFile(HttpServletResponse response,String name,String filePath);
void uploadResource(MultipartFile file,String filePath);
}

@ -185,7 +185,6 @@ public class LocalFileUtil implements IFileUtil{
String substring = name.substring(0, name.lastIndexOf("."));
InputStream fis = null;
try {
response.setContentType("application/octet-stream");
@ -207,4 +206,27 @@ public class LocalFileUtil implements IFileUtil{
}
}
}
@Override
public void uploadResource(MultipartFile file, String relativePath) {
Assert.isTrue(!file.isEmpty(), "文件不存在");
try {
// 创建目录如果不存在
File directory = new File(relativePath);
if (!directory.exists()) {
directory.mkdirs();
}
// 设置目标文件路径
String fileName = file.getOriginalFilename();
File destFile = new File(relativePath + File.separator + fileName);
file.transferTo(destFile);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("上传文件失败,FileNotFound错误", e);
} catch (IOException e) {
throw new IllegalArgumentException("上传文件失败,IO错误", e);
}
}
}

Loading…
Cancel
Save