【问题标题】:Spring boot React js Upload fileSpring Boot React js 上传文件
【发布时间】:2020-04-06 19:20:47
【问题描述】:

你好我需要用spring boot打开excel文件并在数据库中添加数据, 但我收到此错误:构造函数 File(InputStream) 未定义

控制器:

@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;

}

前端派对:

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)=>{})
}

形式:

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>

请问我应该做什么,我需要打开文件 excel 并在我的数据库中添加数据,但是当我尝试打开文件时,我得到错误我应该做什么!

【问题讨论】:

    标签: java reactjs spring-boot file-upload


    【解决方案1】:

    您收到构造函数未定义错误,因为 java File 类没有需要流的构造函数。见File class constructors

    另外,当您直接使用 multipart 获取文件时,为什么需要再次加载它?

    用于使用 OPCPackage refer this thread打开文件

    【讨论】:

    • 我需要打开文件我应该怎么做??
    猜你喜欢
    • 2021-03-01
    • 2020-05-23
    • 2018-04-10
    • 2017-12-30
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多