* dataURL to blob, ref to https://gist.github.com/fupslot/5015897
* @param dataURI
* @returns {Blob}
*/
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], {type: mimeString});
}
* 发送消息
* @param taskValue
*/
sendMessage() {
let dateTime = this.dateFromat.FormatDate(new Date());
let value = $('#message-boxID').html();
let isImg = value.includes('<img');
if (isImg) {
let formData = new FormData();
let dataURL="";
let src=$(value)[0].src;
if(src.includes('data:images')){
dataURL=src;
let blob = dataURItoBlob(dataURL);
formData.append('file', blob);
}else if(src.includes('blob:http')){
for(let i = 0; i < this.files.length; i++) {
formData.append('file', this.files[i], this.files[i].name);
}
}
this.uploadFileService.uploadPic(formData).then(result=>{
console.log(result);
}).catch(err=>{
console.log('图片上传失败'+err);
})
}else{
}
}