在春季休息多部分图片上传api获得不良请求

时间:2015-07-30 12:40:59

标签: java spring rest gridfs rest-client

这对我来说是一个非常戏剧性的情况,我不知道为休息客户提供有效负载是什么错误,因为我得到" 400:BAD REQUEST" 例外。下面是代码,请帮我解决一下,

@RequestMapping(value = "/uploadQuestionImg", method = RequestMethod.POST)
    public ResponseEntity<FileMetadata> commonFileUpload(@RequestParam("file") 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);
    } 

这是我传递给其余客户端的有效负载,

enter image description here

1 个答案:

答案 0 :(得分:1)

当您尝试使用API​​不支持的参数请求时,会出现

kIOPMAssertionTypePreventUserIdleSystemSleep错误。在您的情况下,您尝试发布请求,即400: BAD REQUEST。请求应采用格式Multi part file upload request其他服务器将抛出multi part file request

您可以尝试http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically使用此代码测试400: BAD REQUEST