0

Hello i need to open excel file with spring boot and add data in database , but i get this error : The constructor File(InputStream) is undefined

the controller :

@PostMapping("/upload")
public ResponseEntity<?> addRfp  (@RequestParam("file") MultipartFile file) throws IOException, InvalidFormatException  {


    OPCPackage pkg = OPCPackage.open(new File(file.getInputStream()));
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
System.out.print(wb.getAllNames()); 


    return null;

}

the front end partie :

state = {
  file : null
}
handlFile(e){

  let file = e.target.files[0]
  this.setState({file : file})
}

handleUpload(e){

   let file  = this.state.file;
   let formdata  = new FormData()
   formdata.append('file', file)
   formdata.append("name","ELMANDOUR AMINE")
 axios({
  url :'http://localhost:8080/rfp/upload',
  method :'POST',

  data : formdata
 }).then((res)=>{})
}

the form :

input type="file" className="form-control" id="file" name="file"  onChange={(e)=>this.handlFile(e)} required/>
       </div>
       </div>
       <button id="button" type="button" onClick={(e)=>this.handleUpload(e)}>    <img src={add} id="add" alt="Ajouter Region" />  </button>

please what i should to do i need to open the file excel and add the data at my database but when i try to open the file i get error what i should to do please !

1 Answer 1

0

You are getting the constructor undefined error because java File class does not have a constructor which expects streams. See File class constructors

Also when you are getting a file directly using multipart then why you need to load it again?

For opening a file using OPCPackage refer this thread

Sign up to request clarification or add additional context in comments.

1 Comment

i need the open the file what i should to do ??

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.