function
sumitImageFile(base64Codes){
var
form=document.forms[0];
var
formData =
new
FormData(form);
formData.append(
"imageName"
,convertBase64UrlToBlob(base64Codes));
$.ajax({
url : form.action,
type :
"POST"
,
data : formData,
dataType:
"text"
,
processData :
false
,
contentType :
false
,
success:
function
(data){
window.location.href=
"${ctx}"
+data;
},
xhr:
function
(){
var
xhr =
new
XMLHttpRequest();
xhr.upload.addEventListener(
"progress"
,
function
(evt){
if
(evt.lengthComputable) {
var
percentComplete = Math.round(evt.loaded * 100 / evt.total);
console.log(
"正在提交."
+percentComplete.toString() + &
#39;%'); //在控制台打印上传进度
}
},
false
);
return
xhr;
}
});
}
function
convertBase64UrlToBlob(urlData){
var
bytes=window.atob(urlData.split(&
#39;,')[1]); //去掉url的头,并转换为byte
var
ab =
new
ArrayBuffer(bytes.length);
var
ia =
new
Uint8Array(ab);
for
(
var
i = 0; i < bytes.length; i++) {
ia[i] = bytes.charCodeAt(i);
}
return
new
Blob( [ab] , {type : &
#39;image/png'});
}