1、前端提交base64数据,代码如下
var dataUrl = $('#canvas').getDataUrl(); var img = $('<img>').attr('src', dataUrl); //显示图片 var oMyForm = new FormData(); //创建formdata var blobBin = dataURLtoBlob(dataUrl); //base64转换blob oMyForm.append("blobObject", blobBin); //想formData添加blob数据 $.ajax({ url: $.getUrl()+"activity/updateImg", type: "POST", data: oMyForm, async: false, cache: false, contentType: false, processData: false, success: function (msg) { console.log("yes"); } }); //**dataURL to blob** dataURL转换blob function dataURLtoBlob(dataurl) { 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); } return new Blob([u8arr], { type: mime }); }
2、jfinal后端controller里要怎么取?
想把“blobObject”里的数据拿过来,存为图片文件,现在数据不知道要怎么拿到?