Current request is not a multipart request,

写在文件上传接口时,传入参数有@RequestParam和@RequestBody
在这里插入图片描述
就会报:Current request is not a multipart request
因为RequestParam和RequestBody不能同时存在

有三种种解决方案:
第一种就是把DocumentSignAddCmd 参数全部拆出来使用@RequestParam来传输
如下图
在这里插入图片描述
第二种方案:使用json方式传输
在这里插入图片描述
第三种:把MultipartFile放入到DocumentSignAddCmd中去了,
必须使用@ModelAttribute 来接收
在这里插入图片描述
前端的代码的方式

<body>
    <div id="form">
        提交apk文件:<br />
        <label id="uploadArea" class="upload-area" for="uploadInput">+</label>
        <input name="file" id="uploadInput" type="file" style="display:none;" accept="." onchange="changeInput(this)" />
        <br />
        名称:<input name="operatorName" id="operatorName" class="upload-text" />
        <br />
        <button class="upload-button" onclick="submitForm()">提交</button>
    </div>
    <script>
        function changeInput(input) {
            document.getElementById('operatorName').value = input.files[0].name;
        }
        function submitForm() {
            var input = document.getElementById('uploadInput')
            if (input.files.length > 0) {
                var file = input.files[0]
                console.dir(file);
                var form = document.getElementById('form');
                var data = new FormData();
                data.append('file', file)
                data.append('operatorName', document.getElementById('operatorName').value)
                var xhr = new XMLHttpRequest();
                // xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");  // 将参数解析成传统form的方式上传
                xhr.open('post', 'http://xx.xxx.xxx.xx:8821/version/save', true);
                xhr.onload = function () {
                    alert('上传成功')
                };//上传成功事件监听
                xhr.onerror = function () {
                    alert('上传失败')
                }; //上传失败事件监听
                xhr.send(data);
                input.value = "";
            } else {
                alert('请上传文件')
            }
        }
    </script>
</body>
  • 19
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值