add FileController
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.olympus.hermione.controllers;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.olympus.dto.FileUploadDTO;
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
import com.olympus.model.apollo.KSIngestionInfo;
|
||||
|
||||
@RestController
|
||||
public class FileController {
|
||||
|
||||
private static final String UPLOAD_DIR = "C:\\mnt\\hermione_storage\\documents\\file_input_scenarios\\";
|
||||
|
||||
@PostMapping("/uploadListFiles")
|
||||
public ResponseEntity<String> uploadFiles(
|
||||
@RequestParam("MultiFileUpload") List<MultipartFile> files) {
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
int randomNum = new Random().nextInt(1000); // Numero random tra 0 e 999
|
||||
|
||||
// Crea un nome di cartella basato sulla data e sul numero randomico
|
||||
String folderName = timestamp + "_" + randomNum;
|
||||
File folder = new File(UPLOAD_DIR + folderName);
|
||||
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs(); // Crea la cartella se non esiste
|
||||
}
|
||||
|
||||
try {
|
||||
// Salva ogni file nella cartella
|
||||
for (MultipartFile file : files) {
|
||||
// Path path = Paths.get(UPLOAD_DIR + file.getOriginalFilename());
|
||||
// file.transferTo(path);
|
||||
String fileName = file.getOriginalFilename();
|
||||
File destFile = new File(folder, fileName);
|
||||
file.transferTo(destFile);
|
||||
}
|
||||
return ResponseEntity.ok(folderName);
|
||||
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body("Error uploading files: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user