no multipart boundary was found

1. 问题描述

使用Postman上传图片时,服务器报错:the request was rejected because no multipart boundary was found。

2. 问题解决

  1. stack overflow提供的解决方案

    The problem isn’t in your code - it’s in your request.

    这个问题产生的原因不是代码,而是请求的问题。

    its only work in postman not working with other tools like “Advance rest client”

    这个问题仅仅出现在postman不会出现在像Advance rest client这些工具

    The problem is that you are setting the by yourself, let it be blank. Google Chrome will do it for you. The multipart needs to know the file boundary, and when you remove the , Postman will do it automagically for you.

    这个问题是因为你自定义设置了content-type属性,但是实际上谷歌浏览器会自动帮你添加该属性,multipart需要自定文件的边界。你需要移除content-type属性,让postman帮你自动配置。

    原文链接

  2. 我的解决方案

    结合上面的解答,发现我在使用postman上传文件时:在header配置了content-type的类型。

    但是当我删除了它,服务器又给我报了:Current request is not a multipart request

    于是我推断是否是因为我文件上传的方式不对,于是我换了另外一种方式,果然,请求成功了。

    一开始我使用binary方式上次文件

    在这里插入图片描述

    多次报 not a multipart request之后我换成了form-data方式,果然成功

    在这里插入图片描述

3. 总结

postman使用form-data方式上次图片时会自动配置content-type,不需要手动添加,手动添加会导致不知道边界。

上传图片是要使用form-data而不是binary。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐