Search code examples
springxssfpoi-hssf

get complete address of a file


i need to get the full address of a file which needs to be uploaded by the user using browse button. i tried getAbsolutePath, getAbsoluteFile, getCanonicalPath but they all are giving tomcat/bin location. i need the full path of the file which is to be uploaded.

MultipartFile doc_file = studentInfoBean.getUploadedDocument();

String fileName = doc_file.getOriginalFilename();
String fileExtension = FilenameUtils.getExtension(fileName);
File file = new File(fileName);
File path = file.getAbsoluteFile();
//String path = path.toString()

thank you


Solution

  • You'll probably want to use MultipartFile.transferTo(File dest) to save the uploaded file locally. You can then do your conversion, and whatever you need to do with your .csv file (store it somewhere, send it back to the client, etc.) So the full code might be:

    MultipartFile doc_file = studentInfoBean.getUploadedDocument();
    File temp_file = new File(doc_file.getOriginalFilename());
    doc_file.transferTo(temp_file);
    //convert doc_file to .csv
    //store locally permanently or return to client