Skip to content

Commit 83fb5d5

Browse files
authored
Merge pull request #2107 from feitianbubu/pr/fix--dup-key-upload
feat: add check for existing file key before upload
2 parents a1070a6 + 32f21d8 commit 83fb5d5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

server/service/example/exa_file_upload_download.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
1010
"github.com/flipped-aurora/gin-vue-admin/server/model/example/request"
1111
"github.com/flipped-aurora/gin-vue-admin/server/utils/upload"
12+
"gorm.io/gorm"
1213
)
1314

1415
//@author: [piexlmax](https://github.com/piexlmax)
@@ -107,7 +108,13 @@ func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader,
107108
Key: key,
108109
}
109110
if noSave == "0" {
110-
return f, e.Upload(f)
111+
// 检查是否已存在相同key的记录
112+
var existingFile example.ExaFileUploadAndDownload
113+
err = global.GVA_DB.Where("`key` = ?", key).First(&existingFile).Error
114+
if errors.Is(err, gorm.ErrRecordNotFound) {
115+
return f, e.Upload(f)
116+
}
117+
return f, err
111118
}
112119
return f, nil
113120
}

0 commit comments

Comments
 (0)