mirror of
https://github.com/doocs/md.git
synced 2024-11-24 19:10:34 +08:00
fix: update upload method
This commit is contained in:
parent
7e333ed54c
commit
ec2ae4aa51
@ -3,27 +3,24 @@ const githubResourceUrl = 'raw.githubusercontent.com/filess/images/master/';
|
|||||||
const cdnResourceUrl = 'cdn.jsdelivr.net/gh/filess/images/';
|
const cdnResourceUrl = 'cdn.jsdelivr.net/gh/filess/images/';
|
||||||
|
|
||||||
export function uploadImgFile(file) {
|
export function uploadImgFile(file) {
|
||||||
|
|
||||||
return new Promise((resolve, reject)=> {
|
|
||||||
const checkImageResult = isImageIllegal(file);
|
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const checkImageResult = isImageIllegal(file);
|
||||||
if (checkImageResult) {
|
if (checkImageResult) {
|
||||||
reject(checkImageResult);
|
reject(checkImageResult);
|
||||||
} else {
|
return;
|
||||||
const imgFile = new FileReader();
|
}
|
||||||
imgFile.readAsDataURL(file);
|
const imgFile = new FileReader();
|
||||||
|
imgFile.readAsDataURL(file);
|
||||||
imgFile.onload = function() {
|
|
||||||
const base64Content = this.result.split(',').pop();
|
|
||||||
fileApi.fileUpload(base64Content, file.name).then(res=> {
|
|
||||||
const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl)
|
|
||||||
|
|
||||||
resolve(imageUrl);
|
|
||||||
}).catch(err => {
|
|
||||||
console.log(err.message)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
imgFile.onload = function () {
|
||||||
|
const base64Content = this.result.split(',').pop();
|
||||||
|
fileApi.fileUpload(base64Content, file.name).then(res => {
|
||||||
|
const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl);
|
||||||
|
resolve(imageUrl);
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err.message)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -36,4 +33,4 @@ export function isImageIllegal(file) {
|
|||||||
return '由于公众号限制,图片大小不能超过 5.0M';
|
return '由于公众号限制,图片大小不能超过 5.0M';
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user