想利用$http来提交input type=file,用FormData来封装file,最开始时利用$http提交的时候没有设置headers中的Content-type这一项,提交的时候spring提示MultipartFile找不到边界,看了一下Chrome的网络属性Content-Type 属性application/json,google了一下之后把Content-Type设置为multipart/form-data,看了一下这次请求的Content-Type是multipart/form-data,但是还是报相同的错。索性利用Form本身的submit请求了一次,发现请求的Content-Type属性中有一个boundary的标识。后来又去搜索了一下,在这个地方找到了答案https://uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs,原来将Content-Type设置为undefined,angular就会帮你自动设置好边界了,设置为multipart/form-data反而不能设置边界,注意设置的时候是undefined
不是"undefined"。
angular 采用$http 上传file spring 提示找不到boundary
最新推荐文章于 2021-09-13 12:56:23 发布
本文探讨了在AngularJS中使用$http提交inputtype=file时遇到的问题,特别是关于设置正确的Content-Type以避免MultipartFile找不到边界的错误。通过设置Content-Type为undefined,AngularJS自动设置了边界标识,解决了请求发送过程中的问题。
8386

被折叠的 条评论
为什么被折叠?



