0

Here is the Upload Controller that I am trying to read the .ods file with. I am reading each cell one by one through Java Workbook.

@RestController
public class UploadController {
    @ApiOperation(value = "Upload mappings excel file", notes = "Uploads the excel file and stores on couchbase")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "File uploaded successfully"),
            @ApiResponse(code = 500, message = "Internal server error"),
            @ApiResponse(code = 400, message = "Bad request")
    })

    @RequestMapping(value = "/upload", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = "multipart/form-data")
    public void uploadMappingsExcel(
            @ApiParam(value = "file", example = "user.ods", required = true)
            @RequestParam(value = "file", required = false) MultipartFile multipartFile) throws IOException{
        Path  path = null;
        for(MultipartFile file : Collections.singleton(multipartFile)) {
            path = Paths.get(file.getOriginalFilename());
            Files.write(path,file.getBytes());
        }
        FileInputStream file = new FileInputStream(path.toString());
        XSSFWorkbook workbook = new XSSFWorkbook(file);

        Sheet sheet = workbook.getSheetAt(0);
        DataFormatter dataFormatter = new DataFormatter();
        Iterator<Row> rowIterator = sheet.iterator();

        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                String cellValue = dataFormatter.formatCellValue(cell);
                System.out.print(cellValue + "\t");
            }
            System.out.println();

        }

    }

I am trying to upload the .ods file through Postman.

Serban Petrescu
  • 5,127
  • 2
  • 17
  • 34
Guneet
  • 209
  • 1
  • 4
  • 12
  • IMO, the controller method contents are irrelevant. To me, it looks like you are manually configuring MVC / the dispatcher servlet and are missing the configuration for multi part support (which is normally provided out of the box by boot's dispatcher servlet auto configuration: https://github.com/spring-projects/spring-boot/blob/a097f923c1a096090535ef21e23a27fba5edfc07/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java#L126). Did you by chance disable any auto-configurations? – Serban Petrescu Jun 23 '18 at 10:57
  • I did not disable anything as far as i can recall//// – Guneet Jun 23 '18 at 10:59
  • Well, I would suggest that you start your spring boot app with debug mode on (see https://stackoverflow.com/questions/47101743/how-to-display-auto-configuration-report-when-running-a-spring-boot-application) to see if the `DispatcherServletAutoConfiguration` is actually loaded or not. – Serban Petrescu Jun 23 '18 at 11:04
  • DispatcherServletAutoConfiguration matched: - ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet'; ConditionalOnMissingClass did not find unwanted class (OnClassCondition) - found ConfigurableWebEnvironment (OnWebApplicationCondition) – Guneet Jun 23 '18 at 11:11
  • DispatcherServletAutoConfiguration.DispatcherServletConfiguration matched: - ConditionalOnClass found required class 'javax.servlet.ServletRegistration'; ConditionalOnMissingClass did not find unwanted class (OnClassCondition) - Default DispatcherServlet did not find dispatcher servlet beans (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition) – Guneet Jun 23 '18 at 11:11
  • DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration matched: - ConditionalOnClass found required class 'javax.servlet.ServletRegistration'; ConditionalOnMissingClass did not find unwanted class (OnClassCondition) - DispatcherServlet Registration did not find servlet registration bean (DispatcherServletAutoConfiguration.DispatcherServletRegistrationCondition) – Guneet Jun 23 '18 at 11:12
  • DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration#dispatcherServletRegistration matched: - ConditionalOnBean (names: dispatcherServlet; types: org.springframework.web.servlet.DispatcherServlet; SearchStrategy: all) found bean 'dispatcherServlet' (OnBeanCondition) – Guneet Jun 23 '18 at 11:12
  • Got these on enabling debug mode – Guneet Jun 23 '18 at 11:13

0 Answers0