Merge pull request #2 from kshitij-ka/main
This commit is contained in:
@@ -19,6 +19,11 @@ import java.security.PrivateKey;
|
|||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.util.List;
|
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.getPrivateKeyForUser;
|
||||||
import static com.skycrate.backend.skycrateBackend.utils.KeyUtil.getPublicKeyForUser;
|
import static com.skycrate.backend.skycrateBackend.utils.KeyUtil.getPublicKeyForUser;
|
||||||
|
|
||||||
@@ -86,15 +91,31 @@ public class HDFScontroller {
|
|||||||
|
|
||||||
|
|
||||||
@PostMapping("/downloadFile")
|
@PostMapping("/downloadFile")
|
||||||
public ResponseDTO downloadFile(
|
public ResponseEntity<?> downloadFile(
|
||||||
@RequestParam String hdfsPath,
|
@RequestParam String hdfsPath,
|
||||||
@RequestParam String localPath,
|
|
||||||
@RequestParam String username) {
|
@RequestParam String username) {
|
||||||
try {
|
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);
|
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) {
|
} 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ spring.jpa.properties.hibernate.format_sql=true
|
|||||||
spring.jpa.open-in-view=false
|
spring.jpa.open-in-view=false
|
||||||
logging.level.org.springframework.security.config.annotation.authentication.configuration.InitializeUserDetailsBeanManagerConfigurer=ERROR
|
logging.level.org.springframework.security.config.annotation.authentication.configuration.InitializeUserDetailsBeanManagerConfigurer=ERROR
|
||||||
|
|
||||||
server.port=8081
|
server.port=8080
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
-13
@@ -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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user