春季启动POST PDF内容类型'不支持application / pdf

时间:2019-03-12 13:56:59

标签: java rest spring-boot

我正在尝试建立一个后端,在其中发送两个PDF并与之一起工作。为此,我必须实现REST服务,但无法接收它们。

PostMapping

@PostMapping("/post")
    CompareJob compareJob(@RequestBody File file1) {
        System.out.print("Received File: " + file1);
        CompareJob compareJob = new CompareJob();
        return compareJob;
    }

要执行POST请求,我使用了设置以下内容的Postman:

标题->内容类型:application / pdf

Body-> Binary:testPDF.pdf

这是我得到的答复:

{
    "timestamp": "2019-03-12T13:55:12.898+0000",
    "status": 415,
    "error": "Unsupported Media Type",
    "message": "Content type 'application/pdf;charset=UTF-8' not supported",
    "path": "/post"
}

我是REST服务的新手,将不胜感激一些提示。

感谢您的帮助!

在amin10043建议之后进行编辑:

@PostMapping("/post")
    CompareJob compareJob(@RequestParam("file1") MultipartFile file1) {
        System.out.print("Received File: " + file1);
        CompareJob compareJob = new CompareJob();
        return compareJob;
    }

阅读后,我不应该在邮递员中检查Content-Type,我得到以下响应:

{
    "timestamp": "2019-03-12T14:37:52.765+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Current request is not a multipart request",
    "path": "/post"
}

我的错是我将pdf作为二进制文件而不是作为邮递员中的表格数据上传。必须这样设置:https://snag.gy/H4w5S8.jpg

0 个答案:

没有答案