Tomcat: необходимая часть запроса 'file' отсутствует - PullRequest
0 голосов
/ 30 октября 2018

Я использую Spring Boot для проверки работоспособности загрузки и получаю сообщение об ошибке «Обязательный параметр MultipartFile» файл «отсутствует». когда он развернул внешний сервер Tomcat. но он правильно работает с плагином tomcat с весенней загрузкой Ниже приведены 1) JSP, 2) Контроллер 3) Свойство Config

1)

<form id="initialUploadForm" action="${root}/upload/uploadCapFile" enctype="multipart/form-data" method="post">
                <table align="left" width="50%" cellspacing="0" cellpadding="5"
                       border="0" class="formTable">
                    <tr>
                        <td><label class="">Add Cap File : </label></td>
                        <td><input type="file" name="file" style="width:100%;"/></td>
                    </tr>
                    <tr>
                        <td colspan="2">&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input class="btn btn-success" type="submit"
                                   value="Upload Data" id="btnInitialUpload"/></td>
                    </tr>
                    <tr>
                        <td colspan="2">&nbsp;</td>
                    </tr>
                </table>
</form>

2)

@RequestMapping(value = "uploadCapFile", method = RequestMethod.POST)
        ModelAndView uploadCapFileData(@RequestParam("file") MultipartFile file, Model model) {
            try {
                if (log.isDebugEnabled()) log.debug("UploadController  calling : ");

                System.out.println("File Name : " + file.getOriginalFilename());
                long lStartTime = new Date().getTime();
                    if (!file.isEmpty()) {
                        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
                        if (extension.equals(Constants.FILE_FORMAT)) {
                            File convFile = convertFile(file);
                            InputStream in = new FileInputStream(convFile);
                            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                            StringBuilder out = new StringBuilder();
                            String line;
                            while ((line = reader.readLine()) != null) {
                                out.append(line);
                            }
                            if (isProdUpdate == 1) {
                                hotelService.updateAgentMarkup(out.toString());
                            } else {
                                hotelService.updateHotelData(out.toString());
                            }
                        } else {
                            log.error("Invalid File Format ! File Format is :" + Constants.FILE_FORMAT);
                        }
                    } else {
                        log.error("File is missing ! Can not be Process");
                    }


                long lEndTime = new Date().getTime();
                long output = TimeUnit.MILLISECONDS.toSeconds(lEndTime - lStartTime);
                processingTime = String.valueOf(output);
            } catch (IOException e) {
                log.error("Error occurred while calling the UploadController : " + e);
            } catch (TalcacheException e) {
                log.error("Error occurred while calling the UploadController  : " + e.getErrorMsg());
            } catch (Exception e) {
                log.error("Error occurred while calling the UploadController : " + e);
            }
    }

3)

 spring.servlet.multipart.enabled=true
 spring.servlet.multipart.file-size-threshold=5KB
 spring.servlet.multipart.max-file-size=200MB
 spring.servlet.multipart.max-request-size=215MB

Ответы [ 2 ]

0 голосов
/ 31 октября 2018

Поместите этот код в файл конфигурации

@Bean
public CommonsMultipartResolver multipartResolver() {
  CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
  multipartResolver.setMaxUploadSize(-1);
  return multipartResolver;
        }
0 голосов
/ 30 октября 2018

Попробуйте добавить multipart/form-data в сигнатуру метода.

@RequestMapping(value = "uploadCapFile", method = RequestMethod.POST,headers = "content-type=multipart/form-data")
...