File Upload/Download with Folders on Web

31 Views Asked by At

Hey I'm currently learning developing in general and

I currently have an springboot project with thymeleaf and I try to use an AdminLTE template (Simple Tables) to display uploaded files in different Folders that I can expand etc.

But that's where I'm struggling because currently I only have the ability to upload files, display them on another site and download/delete them.

I tried to find some examples for this in the internet but couldn't find anything that's somewhat similiar to orientate me at it.

1

There are 1 best solutions below

0
Ricardo Gellman On

Here is a part of one of my implementations with controller and view, please revalidate, as it has couple years

@Controller
public class FileController {

    @Autowired
    private FileService fileService;

    @GetMapping("/files")
    public String listFiles(Model model) {
        List<File> files = fileService.getAllFiles(); 
        model.addAttribute("files", files);
        return "files"; // put your thymeleaf name
    }

}

And UI

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AdminLTE Integration</title>
    <link rel="stylesheet" href="/adminlte/css/adminlte.min.css">
</head>
<body>
    <script src="/adminlte/js/adminlte.min.js"></script>
</body>
</html>


<div>
    <table>
        <thead>
            <tr>
                <th>File Name</th>
                <th>Size</th>
            </tr>
        </thead>
        <tbody>
            <tr th:each="file : ${files}">
                <td th:text="${file.name}"></td>
                <td th:text="${file.size}"></td>
            </tr>
        </tbody>
    </table>
</div>

Also You need to create a specific directory in your project to hold these files, such as src/main/resources/static/adminlte.