多部分请求在春假休息服务中不起作用

时间:2015-09-11 08:54:39

标签: spring mongodb rest gridfs

我不知道在发送上传文件的请求时我犯了什么错误,请看看并建议。

web.xml文件中的多部分过滤器配置

<filter>
    <filter-name>multipartFilter</filter-name>
    <filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>multipartFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

FileController.java

@RequestMapping(value = "/uploadQuestionImg", method = RequestMethod.POST)
    public ResponseEntity<FileMetadata> commonFileUpload(@RequestParam("image") MultipartFile file) {

        FileMetadata fileInfo = null;
        HttpStatus statusCode = HttpStatus.BAD_REQUEST;
        if (!file.isEmpty()) {
            try {
                FileInfoService reqFile = createFileInfo(file, "");
                fileInfo = (FileMetadata) operations.store(file.getInputStream(), reqFile);
                statusCode = HttpStatus.OK;
            } catch (Exception e) {
                logger.warn("Exception occured", e);
                statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
            }
        } else {
            logger.warn("Invalid request");
        }
        return new ResponseEntity<FileMetadata>(fileInfo, statusCode);
    }

Multipart Resolver(在调度程序servlet中实现)

<bean id="filterMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <property name="maxUploadSize" value="100000000" />
</bean>

我无法使用Chrome rest插件发送请求,它说: 400错误请求,我已检查过URL&amp;内容类型(multipart / form-data)&amp;在附件中的文件,每件事看起来都没问题。请建议。

0 个答案:

没有答案