hookehuyr

fix 图片重复上传问题处理

......@@ -109,7 +109,7 @@ const uuid = () => {
return uuid;
};
const uploadQiniu = async (file, token, filename) => {
const uploadQiniu = async (file, token, filename, md5) => {
let formData = new FormData();
formData.append("file", file); // 通过append向form对象添加数据
formData.append("token", token);
......@@ -126,8 +126,9 @@ const uploadQiniu = async (file, token, filename) => {
if (filekey) {
// 保存图片
const { data } = await saveFileAPI({
filename,
filekey,
hash,
hash: md5,
format: image_info.format,
height: image_info.height,
width: image_info.width,
......@@ -140,7 +141,6 @@ const uploadQiniu = async (file, token, filename) => {
const handleUpload = async (files) => {
// 上传图片流程
loading.value = true;
// let imgUrl = "";
// 获取HASH值
// const hash = getEtag(files.content);
return new Promise((resolve, reject) => {
......@@ -156,14 +156,22 @@ const handleUpload = async (files) => {
// 获取七牛token
const filename =
"uploadForm/" + formCode + "/" + uuid() + "." + files.file.name.split(".")[1];
const { token, key, code } = await qiniuTokenAPI({
const getToken = await qiniuTokenAPI({
name: filename,
hash: md5,
});
// 文件上传七牛云
let imgUrl = "";
// 第一次上传
if (getToken.token) {
files.status = "uploading";
files.message = "上传中...";
const imgUrl = await uploadQiniu(files.file, token, filename);
imgUrl = await uploadQiniu(files.file, getToken.token, filename, md5);
}
// 重复上传
if (getToken.data) {
imgUrl = getToken.data;
}
resolve(imgUrl);
},
(process) => {
......