Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2022-12-02 15:28:34 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
799d64bb6f30433220dcbfc9605decd44ec7638f
799d64bb
1 parent
39255749
fix 图片重复上传问题处理
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
src/components/ImageUploaderField/index.vue
src/components/ImageUploaderField/index.vue
View file @
799d64b
...
...
@@ -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,
});
// 文件上传七牛云
files.status = "uploading";
files.message = "上传中...";
const imgUrl = await uploadQiniu(files.file, token, filename);
let imgUrl = "";
// 第一次上传
if (getToken.token) {
files.status = "uploading";
files.message = "上传中...";
imgUrl = await uploadQiniu(files.file, getToken.token, filename, md5);
}
// 重复上传
if (getToken.data) {
imgUrl = getToken.data;
}
resolve(imgUrl);
},
(process) => {
...
...
Please
register
or
login
to post a comment