简体   繁体   English

Spring Boot POST PDF内容类型'application / pdf不支持

[英]Spring boot POST PDF Content type 'application/pdf not supported

I'm trying to have a backend where I send two PDF's and work with those. 我试图在后端发送两个PDF并与之一起工作。 For that I have to implement a REST service but I'm not able to receive them. 为此,我必须实现REST服务,但无法接收它们。

PostMapping PostMapping

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

To do the POST requests I use Postman where I've set following things: 要执行POST请求,我使用Postman进行以下设置:

Headers -> Content-Type: application/pdf 标头->内容类型:应用程序/ pdf

Body -> Binary: testPDF.pdf 正文->二进制文件:testPDF.pdf

This is the response I'm getting: 这是我得到的答复:

{
    "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"
}

I'm very new to REST services and would greatly appreciate some hints what is wrong. 我是REST服务的新手,不胜感激一些提示是怎么回事。

Thanks for any help! 谢谢你的帮助!

Edit after amin10043 suggestion: 在amin10043建议后编辑:

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

After reading I should not check Content-Type in Postman I'm getting this response: 阅读后,我不应该在邮递员中检查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"
}

My fault was that I uploaded the pdf as a binary and not as form-data in postman. 我的错是我将pdf作为二进制文件而不是邮递员中的表格数据上传。 Must be set like this: https://snag.gy/H4w5S8.jpg 必须这样设置: https : //snag.gy/H4w5S8.jpg

如果要上传文件,最好使用Multipartfile ,也请将输入参数从@RequesBody@RequestParam("your parameter name") ,这样邮递员就可以向请求中添加正确的标头并且应该可以使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 终端中的POST请求不支持Spring Boot内容类型'text / plain' - Spring Boot Content type 'text/plain' not supported in POST request in terminal 如何添加pdf / byte []消息读取器进行交换策略,内容类型“ application / pdf”不受支持 - How to add pdf/byte[] messge reader to exchangeStrategies, Content type 'application/pdf' not supported POST上的Spring MVC不支持内容类型'application / json' - Content type 'application/json' not supported in Spring MVC on POST liferay 6.0.6不支持application / pdf的mime类型 - application / pdf is not a supported mime type at liferay 6.0.6 生产 = "application/pdf" 不适用于 Spring Boot - produces = "application/pdf" not working on Spring Boot Spring Boot - 不支持内容类型“application/x-www-form-urlencoded;charset=UTF-8” - Spring Boot - Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported Spring 启动 controller 调用不支持内容类型 'application/json;charset=UTF-8' - Content type 'application/json;charset=UTF-8' not supported with Spring boot controller call Spring MVC - 不支持内容类型“应用程序/json” - Spring MVC - Content type 'application/json' not supported spring boot mvc - 不支持内容类型'application / json; charset = UTF-8' - spring boot mvc - Content type 'application/json;charset=UTF-8' not supported 从外部 Rest API 在 PDF 内容类型中提取内容的正确方法是什么 - What is the correct way to extract bytes of a response from an external Rest API producing content in PDF Content Type in Spring Boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM