Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring Boot+;上载时Excel文件损坏;角JS_Java_Angularjs_Spring_Spring Boot - Fatal编程技术网

Java 使用Spring Boot+;上载时Excel文件损坏;角JS

Java 使用Spring Boot+;上载时Excel文件损坏;角JS,java,angularjs,spring,spring-boot,Java,Angularjs,Spring,Spring Boot,我正在尝试使用angular js+spring boot上传一个excel文件。文件已成功上载,但文件似乎已损坏。我无法打开文件。这是我的密码 index.html <p align="right"> <input type = "file" id="file" name="file"/> <button ng-click="uploadFile()">Upload</button> </p> Controller.

我正在尝试使用angular js+spring boot上传一个excel文件。文件已成功上载,但文件似乎已损坏。我无法打开文件。这是我的密码

index.html

<p align="right">
    <input type = "file" id="file" name="file"/>
    <button ng-click="uploadFile()">Upload</button>
</p>
Controller.java

@RequestMapping(value = "/uploadAsExcel", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<?> uploadFile(@RequestParam("uploadfile") MultipartFile uploadfile) {

    try {
        // Get the filename and build the local file path
        String filename = uploadfile.getOriginalFilename();
        String contentType = uploadfile.getContentType();
        System.out.println("ContentType: "+contentType);
        String filepath = "C:\\Users\\user122\\Documents\\MyFiles\\"+filename;

        //Save the file locally
        BufferedOutputStream stream =
                new BufferedOutputStream(new FileOutputStream(new File(filepath)));
        stream.write(uploadfile.getBytes());
        stream.close();
    }
    catch (Exception e) {
        System.out.println(e.getMessage());
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }

    return new ResponseEntity<>(HttpStatus.OK);
}
@Bean
public CommonsMultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver=new CommonsMultipartResolver();
    //resolver.setDefaultEncoding("utf-8");
    resolver.setMaxUploadSize(-1);
    return resolver;
}
Excel文件上传成功,但当我打开文件时,它显示“文件已损坏”。基本上,我需要使用excel API读取excel文件并执行一些操作

你能请任何人帮忙吗

谢谢, 卡提克

@Bean
public CommonsMultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver=new CommonsMultipartResolver();
    //resolver.setDefaultEncoding("utf-8");
    resolver.setMaxUploadSize(-1);
    return resolver;
}