fix: update upload method

This commit is contained in:
yanglbme 2020-08-29 19:13:52 +08:00
parent 7e333ed54c
commit ec2ae4aa51

View File

@ -6,25 +6,22 @@ export function uploadImgFile(file) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const checkImageResult = isImageIllegal(file); const checkImageResult = isImageIllegal(file);
if (checkImageResult) { if (checkImageResult) {
reject(checkImageResult); reject(checkImageResult);
} else { return;
}
const imgFile = new FileReader(); const imgFile = new FileReader();
imgFile.readAsDataURL(file); imgFile.readAsDataURL(file);
imgFile.onload = function () { imgFile.onload = function () {
const base64Content = this.result.split(',').pop(); const base64Content = this.result.split(',').pop();
fileApi.fileUpload(base64Content, file.name).then(res => { fileApi.fileUpload(base64Content, file.name).then(res => {
const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl) const imageUrl = res.content.download_url.replace(githubResourceUrl, cdnResourceUrl);
resolve(imageUrl); resolve(imageUrl);
}).catch(err => { }).catch(err => {
console.log(err.message) console.log(err.message)
}) })
} }
}
}); });
} }