var base64 = '';
const blob = dataURLToBlob(base64);
const file = blobToFile(blob, 'image.jpg');
uploadImage(file);
function dataURLToBlob(base64) {
const parts = dataURL.split(';base64,');
const contentType = parts[0].split(':')[1];
const byteCharacters = atob(parts[1]);
const byteArrays = [];
for (let i = 0; i < byteCharacters.length; i++) {
byteArrays.push(byteCharacters.charCodeAt(i));
}
return new Blob([new Uint8Array(byteArrays)], { type: contentType });
}
function blobToFile(blob, fileName) {
return new File([blob], fileName, { type: blob.type });
}
function uploadImage(file) {
var formData = new FormData();
formData.append(picFile, file);
$.ajax({
url: /upload/img-upload-local,
type: POST,
async:false,
data: formData,
processData: false,
contentType: false,
success: function(res) {
$(.div1).hide();
$(.div2).hide();
$(#showImg).attr(src,res.url)
$(.imgDiv).show();
closeCamera();
},
error: function() {
alert(上传失败);
}
});
}