0

I want to pass a file path as a String to DAO Class through service Class to store in the mySQL database using REST Controller. I tried with some approach but it's not working. Any idea on this?

@RequestMapping(value="/upload", method=RequestMethod.POST, headers=("content-type=multipart/*"))
public @ResponseBody void handleFileUpload(@RequestParam("file") MultipartFile file) {

    String itr =  file.getOriginalFilename();

    fileMeta = new Document();
    try {
        fileMeta.setBytes(file.getBytes());

        FileCopyUtils.copy(file.getBytes(), new FileOutputStream("D:/temp/files/"+file.getOriginalFilename()));

    } catch (IOException e) {   
        e.printStackTrace();
    }
}
Tsung-Ting Kuo
  • 1,171
  • 6
  • 16
  • 21
Protagonist
  • 1,649
  • 7
  • 34
  • 56

1 Answers1

0
String filePath = String.format("D:%stemp%sfiles%s%s, File.separator, File.separator, File.separator, file.getOriginalFilename());
FileCopyUtils.copy(file.getBytes(), new FileOutputStream(filePath);

FileCopyUtils.copy will write this file bytes to "filePath", according to your request, the rest you need to do it storing this path to mysql db.

Roger Dwan
  • 740
  • 4
  • 6