0

I wrote some code to create a REST api to handle customer's infomation and a file from them,I want to save the file they upload to my local disk on server.My code is as below

 @RequestMapping(value = "/alg", method = RequestMethod.POST)
public String postUsersNewAlg(@RequestParam(value = "file", required = true) CommonsMultipartFile jarfile,
                              @RequestParam(value = "username", required = true) String userName,
                              @RequestParam(value = "output", required = true) String output) {

   //other code handles string infos etc.

    try {
      //get directory path that to save file
      String filePath = PathUtil.getOffAlgJarFilePathRoot();

      //get file path 
      String filePathWhole = null;
      if (!filePath.endsWith(SeparatorUtils.getFileSeparator())) {
        filePathWhole = filePath + SeparatorUtils.getFileSeparator() + algImpl.getOriginalFilename();
         } 
      else {
        filePathWhole = filePath + algImpl.getOriginalFilename();
        }

    FileUtil.copyFile(jarfile, filePath,filePathWhole);
    }
    catch(Exception e){
        e.printStackTrace();
        return e.getMessage();
    }
}

Problem is a java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileUploadException] with root cause.So how can I do this?Thanks in advance.

2
  • if you add commons-fileupload, u'll get an error (File convert). You need this : link Or just change CommonsMultipartFile to MultipartFile. Commented Oct 23, 2017 at 13:56
  • Yes I tried and it works Commented Oct 23, 2017 at 14:17

1 Answer 1

1

Have you tried this one on pom.xml or add commons-fileupload.jar:

 <dependency>
   <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
   <version>1.2.1</version>
 </dependency>
Sign up to request clarification or add additional context in comments.

1 Comment

No , I added this to my pom and changed Commons MultipartFile to MultipartFile and it works, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.