Browse Source

大文件下载失败测试

dev-opt
chenzhihang 6 months ago
parent
commit
67cbd8b0fa
3 changed files with 32 additions and 27 deletions
  1. +2
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java
  2. +1
    -1
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java
  3. +29
    -24
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java

+ 2
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/NewDatasetFromGitController.java View File

@@ -192,8 +192,8 @@ public class NewDatasetFromGitController {

@GetMapping("/downloadSingleFile")
@ApiOperation(value = "下载单个数据集文件", notes = "根据数据集版本表id下载单个数据集文件")
public ResponseEntity<InputStreamResource> downloadDataset(@RequestParam("url") String url) throws Exception {
return newDatasetService.downloadDatasetlocal(url);
public AjaxResult downloadDataset(@RequestParam("url") String url) throws Exception {
return AjaxResult.success(newDatasetService.downloadDatasetlocal(url));
}

@PostMapping("/getVersionsCompare")


+ 1
- 1
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/NewDatasetService.java View File

@@ -27,7 +27,7 @@ public interface NewDatasetService {

List<Map<String, String>> uploadDatasetlocal(MultipartFile[] files, String uuid) throws Exception;

ResponseEntity<InputStreamResource> downloadDatasetlocal(String filePath) throws Exception;
String downloadDatasetlocal(String filePath) throws Exception;

ResponseEntity<InputStreamResource> downloadAllDatasetFilesNew(String name, String identifier, Integer id, String owner, String version, Boolean isPublic) throws IOException, Exception;



+ 29
- 24
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java View File

@@ -81,6 +81,12 @@ public class NewDatasetServiceImpl implements NewDatasetService {
String secretAccessKey;
@Value("${minio.endpoint}")
String endpoint;
@Value("${minio.endpointIp}")
String endpointIp;
@Value("${minio.dataReleaseBucketName}")
private String bucketName;
@Value("${minio.platformDataBucketName}")
private String platformDataBucketName;
@Value("${git.endpoint}")
String gitendpoint;
@Value("${git.cloneEndpoint}")
@@ -89,9 +95,6 @@ public class NewDatasetServiceImpl implements NewDatasetService {
String gitCloneEndpointIp;
@Value("${git.projectDatasetId}")
Integer projectDatasetId;

@Value("${minio.dataReleaseBucketName}")
private String bucketName;
@Value("${git.localPath}")
String localPathlocal;

@@ -597,25 +600,27 @@ public class NewDatasetServiceImpl implements NewDatasetService {
}

@Override
public ResponseEntity<InputStreamResource> downloadDatasetlocal(String filePath) throws Exception {
File file = new File(filePath);

if (!file.exists()) {
throw new FileNotFoundException("File not found: " + filePath);
}

InputStreamResource resource = new InputStreamResource(new FileInputStream(file));

HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName());
headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length()));
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);

return ResponseEntity.ok()
.headers(headers)
.contentLength(file.length())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
public String downloadDatasetlocal(String filePath) throws Exception {
// File file = new File(filePath);
//
// if (!file.exists()) {
// throw new FileNotFoundException("File not found: " + filePath);
// }
//
// InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
//
// HttpHeaders headers = new HttpHeaders();
// headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName());
// headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length()));
// headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
//
// return ResponseEntity.ok()
// .headers(headers)
// .contentLength(file.length())
// .contentType(MediaType.APPLICATION_OCTET_STREAM)
// .body(resource);
String[] split = filePath.split("/");
return endpointIp + "/" + bucketName + "/" + platformDataBucketName + "/" + String.join("/", Arrays.copyOfRange(split, 3, split.length));
}

@Override
@@ -756,7 +761,7 @@ public class NewDatasetServiceImpl implements NewDatasetService {
}

@Override
public void privateToPublic(NewDatasetVo newDatasetVo) throws Exception {
public void privateToPublic(NewDatasetVo newDatasetVo) throws Exception {
//获取版本列表信息,每一个版本的配置文件都要更改
String token = gitService.checkoutToken();
List<Map<String, Object>> brancheList = gitService.getBrancheList(token, newDatasetVo.getOwner(), newDatasetVo.getIdentifier());
@@ -781,7 +786,7 @@ public class NewDatasetServiceImpl implements NewDatasetService {
Map<String, Object> param = new HashMap<>();
param.put("id", projectDetail.get("project_id"));
param.put("is_public", true);
gitService.updateProjectDetail(param,newDatasetVo.getOwner(),newDatasetVo.getIdentifier(),token);
gitService.updateProjectDetail(param, newDatasetVo.getOwner(), newDatasetVo.getIdentifier(), token);
}

/**


Loading…
Cancel
Save