canvas对象转换为Blob对象,并且ajax传入后台以MultipartFile接收

3 篇文章 0 订阅

js 代码:

function upload(e) {
    var dataurl=e.toDataURL();
    var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
        bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
    while(n--){
        u8arr[n] = bstr.charCodeAt(n);
    }
    var blob= new Blob([u8arr], {type:mime});
    var fd = new FormData();
    fd.append("file", blob);
    fd.append("wareInfoId",334);
    $.ajax({
        type: "post",
        url: "/user/save/uploadUserCustomPic.do",
        async: true,
        data: fd,
        dataType:"json",
        processData: false,
        contentType: false,
        success: function(data) {
            if(data.result==1){
                alert(data.msg);

            }
        }
    });
}

后台Controller代码

@RequestMapping("save/uploadUserCustomPic")
public  void uploadUserCustomPic(MultipartFile file,Integer wareInfoId) throws IOException, DocumentException {

}

接下来就可以写业务代码了

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值