Search in sources :

Example 1 with UploadFile

use of ua.springboot.web.entity.UploadFile in project Logos_Materials_October_2017 by VolodymyrZavada.

the class UploadFileController method saveFileToDatabase.

@PostMapping("/upload")
public String saveFileToDatabase(@RequestParam("fileUpload") MultipartFile file) throws IOException {
    if (file != null) {
        // id = null
        UploadFile uploadFile = new UploadFile();
        uploadFile.setFileName(file.getOriginalFilename());
        uploadFile.setFileData(file.getBytes());
        uploadFileService.saveFile(uploadFile);
    // uploadFile ->
    }
    return "redirect:/file/upload";
}
Also used : UploadFile(ua.springboot.web.entity.UploadFile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with UploadFile

use of ua.springboot.web.entity.UploadFile in project Logos_Materials_October_2017 by VolodymyrZavada.

the class UploadFileController method showImageFromDB.

@GetMapping("/preview")
public String showImageFromDB(Model model) {
    UploadFile file = fileService.findFileById(1);
    String encodeFile = new String(Base64.encodeBase64(file.getFileData()));
    model.addAttribute("imageSrc", encodeFile);
    return "file/preview";
}
Also used : UploadFile(ua.springboot.web.entity.UploadFile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with UploadFile

use of ua.springboot.web.entity.UploadFile in project Logos_Materials_October_2017 by VolodymyrZavada.

the class UploadFileController method saveFileTODatabase.

@PostMapping("/upload")
public String saveFileTODatabase(@RequestParam("fileUpload") MultipartFile file) throws IOException {
    if (!file.isEmpty() && file != null) {
        UploadFile uploadFile = new UploadFile();
        // System.out.println("ID: " + uploadFile.getId());
        uploadFile.setFileName(file.getOriginalFilename());
        uploadFile.setFileData(file.getBytes());
        fileService.saveFile(uploadFile);
    // System.out.println("ID: " + uploadFile.getId());
    }
    return "redirect:/file/upload";
}
Also used : UploadFile(ua.springboot.web.entity.UploadFile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

UploadFile (ua.springboot.web.entity.UploadFile)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)1