fix upload file

This commit is contained in:
dalia.florinda
2026-01-15 13:34:43 +01:00
parent b86282ce97
commit c5ccf97ff7
2 changed files with 17 additions and 7 deletions

View File

@@ -157,8 +157,16 @@ public class FileService {
// Normalizza il path rimuovendo eventuali separatori doppi o tripli
String normalizedPath = filePath.replaceAll("[\\\\/]+", "/");
// Costruisci il path completo del file
Path file = Paths.get(uploadDir, normalizedPath);
// Check if path is absolute (starts with drive letter or uploadDir)
// If absolute, use it directly; otherwise, combine with uploadDir
Path file;
if (normalizedPath.matches("^[A-Za-z]:/.*") || normalizedPath.startsWith(uploadDir)) {
// Already absolute path - use directly (backward compatibility)
file = Paths.get(normalizedPath);
} else {
// Relative path - combine with uploadDir
file = Paths.get(uploadDir, normalizedPath);
}
logger.info("Upload directory: {}", uploadDir);
logger.info("Normalized relative path: {}", normalizedPath);

View File

@@ -341,8 +341,9 @@ public class ScenarioExecutionService {
if (scenarioExecutionInput.getInputs().containsKey("Folder")) {
folder_name = scenarioExecutionInput.getInputs().get("Folder");
}
// Save only relative path (folder + filename) without uploadDir
scenarioExecutionInput.getInputs().put("SingleFileUpload",
uploadDir + folder_name + "/" + scenarioExecutionInput.getInputs().get("SingleFileUpload"));
folder_name + "/" + scenarioExecutionInput.getInputs().get("SingleFileUpload"));
}
scenarioExecution.setScenarioExecutionInput(scenarioExecutionInput);
@@ -633,20 +634,21 @@ public class ScenarioExecutionService {
List<ScenarioExecution> results = mongoTemplate.find(query, ScenarioExecution.class);
// Remove MultiFileUpload from inputs if present
// Keep MultiFileUpload flag to show download button in frontend
results.forEach(execution -> {
if (execution.getScenarioExecutionInput() != null &&
execution.getScenarioExecutionInput().getInputs() != null &&
execution.getScenarioExecutionInput().getInputs().containsKey("MultiFileUpload")) {
execution.getScenarioExecutionInput().getInputs().put("MultiFileUpload", null);
// Also remove from execSharedMap if it exists
// Set a placeholder value instead of null to indicate file presence
execution.getScenarioExecutionInput().getInputs().put("MultiFileUpload", "uploaded");
if (execution.getExecSharedMap() != null &&
execution.getExecSharedMap().get("user_input") != null) {
HashMap<String, String> userInput = (HashMap<String, String>) execution.getExecSharedMap().get("user_input");
if (userInput.containsKey("MultiFileUpload")) {
userInput.put("MultiFileUpload", null);
userInput.put("MultiFileUpload", "uploaded");
}
}
}