Merge pull request #2 from kshitij-ka/main

This commit is contained in:
vedang29
2025-04-15 21:44:05 +05:30
committed by GitHub
3 changed files with 27 additions and 19 deletions
@@ -19,6 +19,11 @@ import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.List;
import org.springframework.core.io.FileSystemResource; // For FileSystemResource
import org.springframework.core.io.Resource; // For Resource
import org.springframework.http.HttpHeaders; // For HttpHeaders
import java.io.File; // For java.io.File
import static com.skycrate.backend.skycrateBackend.utils.KeyUtil.getPrivateKeyForUser;
import static com.skycrate.backend.skycrateBackend.utils.KeyUtil.getPublicKeyForUser;
@@ -86,15 +91,31 @@ public class HDFScontroller {
@PostMapping("/downloadFile")
public ResponseDTO downloadFile(
public ResponseEntity<?> downloadFile(
@RequestParam String hdfsPath,
@RequestParam String localPath,
@RequestParam String username) {
try {
// Define a temporary local path to download the file
String localPath = "/app/tmp/downloaded/" + new File(hdfsPath).getName(); // Adjust the path as needed
// Download the file from HDFS to the local path
hdfsOperations.downloadFile(hdfsPath, localPath, username);
return new ResponseDTO("File downloaded successfully", true);
// Create a File object for the downloaded file
File file = new File(localPath);
if (!file.exists()) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new ResponseDTO("File not found", false));
}
// Create a Resource from the file
Resource resource = new FileSystemResource(file);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
.body(resource);
} catch (Exception e) {
return new ResponseDTO("Failed to download file: " + e.getMessage(), false);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new ResponseDTO("Failed to download file: " + e.getMessage(), false));
}
}
@@ -128,4 +149,4 @@ public class HDFScontroller {
.body("Failed to list files: " + e.getMessage());
}
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ spring.jpa.properties.hibernate.format_sql=true
spring.jpa.open-in-view=false
logging.level.org.springframework.security.config.annotation.authentication.configuration.InitializeUserDetailsBeanManagerConfigurer=ERROR
server.port=8081
server.port=8080
@@ -1,13 +0,0 @@
package com.skycrate.backend.skycrateBackend;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SkycrateBackendApplicationTests {
@Test
void contextLoads() {
}
}