vue axios post请求发送图片base64编码给后台报错HTTP 错误 414

发布于 2022-09-06 09:19:39 字数 1242 浏览 7 评论 0

使用axios上传base64数据给后台,请求 报错http414

图片描述

图片只有8kb,并不大

onChange(file, fileName){
    const self = this;
    console.log(file);
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onloadend = function() {
        self.form.imgSrc = this.result;
//        Vue.set(this.form,'imgSrc',)
    };
    console.log("1:"+self.form.imgSrc);
},

//上传图片
uploadImg(){
    console.log("2:"+this.form.imgSrc);
    const url ='http://**************';
    this.$axios({
        method: 'post',
        url:url,
        params: {
            is_iso:1,
            img_base64:this.form.imgSrc,
            type:1
        }
    }).then((res)=>{
        console.log("3:"+this.form.imgSrc);
        if(res.data.errCode==0){
            this.$alert(res.data.retData.msg);
            const imgSucUrl = res.data.retData.img_info.img_url;
            this.form.imgSucUrl = imgSucUrl;
            console.log(res.data)
        }else if(res.data.errCode==1){
            this.$alert(res.data.retData.msg);
            console.log(res.data);
        }
    });
},

这是我的上传图片的请求代码

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁对谁错谁最难过 2022-09-13 09:19:39

‘request URI too large’说明你的url长度太大了。

你使用的POST方式,为什么不把图片数据放到请求体中呢?放到url末尾作为参数不合适吧。

建议你把图片数据放到data中。

┊风居住的梦幻卍 2022-09-13 09:19:39
axios.post('api',base64Data)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文