Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loujc2008
gin-vue-admin
提交
0e1d3867
G
gin-vue-admin
项目概览
loujc2008
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0e1d3867
编写于
11月 20, 2019
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加删除文件接口
上级
b7f6eaf6
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
202 addition
and
20 deletion
+202
-20
QMPlusServer/controller/api/fileUploadAndDownload.go
QMPlusServer/controller/api/fileUploadAndDownload.go
+31
-1
QMPlusServer/controller/api/user.go
QMPlusServer/controller/api/user.go
+1
-1
QMPlusServer/controller/servers/upload.go
QMPlusServer/controller/servers/upload.go
+23
-4
QMPlusServer/docs/docs.go
QMPlusServer/docs/docs.go
+51
-5
QMPlusServer/docs/swagger.json
QMPlusServer/docs/swagger.json
+50
-4
QMPlusServer/docs/swagger.yaml
QMPlusServer/docs/swagger.yaml
+31
-3
QMPlusServer/model/dbModel/fileUploadAndDownload.go
QMPlusServer/model/dbModel/fileUploadAndDownload.go
+12
-0
QMPlusServer/router/fileUploadAndDownload.go
QMPlusServer/router/fileUploadAndDownload.go
+3
-2
未找到文件。
QMPlusServer/controller/api/fileUploadAndDownload.go
浏览文件 @
0e1d3867
...
...
@@ -23,7 +23,7 @@ func UploadFile(c *gin.Context) {
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"上传文件失败,%v"
,
err
),
gin
.
H
{})
}
else
{
//文件上传后拿到文件路径
err
,
filePath
:=
servers
.
Upload
(
header
,
USER_HEADER_BUCKET
,
USER_HEADER_IMG_PATH
)
err
,
filePath
,
key
:=
servers
.
Upload
(
header
,
USER_HEADER_BUCKET
,
USER_HEADER_IMG_PATH
)
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"接收返回值失败,%v"
,
err
),
gin
.
H
{})
}
else
{
...
...
@@ -33,6 +33,7 @@ func UploadFile(c *gin.Context) {
file
.
Name
=
header
.
Filename
s
:=
strings
.
Split
(
file
.
Name
,
"."
)
file
.
Tag
=
s
[
len
(
s
)
-
1
]
file
.
Key
=
key
err
:=
file
.
Upload
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"修改数据库链接失败,%v"
,
err
),
gin
.
H
{})
...
...
@@ -43,6 +44,35 @@ func UploadFile(c *gin.Context) {
}
}
// @Tags FileUploadAndDownload
// @Summary 删除文件
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body dbModel.FileUploadAndDownload true "传入文件里面id即可"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"返回成功"}"
// @Router /fileUploadAndDownload/deleteFile [post]
func
DeleteFile
(
c
*
gin
.
Context
)
{
var
file
dbModel
.
FileUploadAndDownload
_
=
c
.
ShouldBind
(
&
file
)
err
,
f
:=
file
.
FindFile
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"删除失败,%v"
,
err
),
gin
.
H
{})
}
else
{
err
=
servers
.
DeleteFile
(
USER_HEADER_BUCKET
,
f
.
Key
)
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"删除失败,%v"
,
err
),
gin
.
H
{})
}
else
{
err
=
file
.
DeleteFile
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"删除失败,%v"
,
err
),
gin
.
H
{})
}
else
{
servers
.
ReportFormat
(
c
,
true
,
fmt
.
Sprintf
(
"删除成功,%v"
,
err
),
gin
.
H
{})
}
}
}
}
// @Tags FileUploadAndDownload
// @Summary 分页文件列表
// @Security ApiKeyAuth
...
...
QMPlusServer/controller/api/user.go
浏览文件 @
0e1d3867
...
...
@@ -136,7 +136,7 @@ func UploadHeaderImg(c *gin.Context) {
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"上传文件失败,%v"
,
err
),
gin
.
H
{})
}
else
{
//文件上传后拿到文件路径
err
,
filePath
:=
servers
.
Upload
(
header
,
USER_HEADER_BUCKET
,
USER_HEADER_IMG_PATH
)
err
,
filePath
,
_
:=
servers
.
Upload
(
header
,
USER_HEADER_BUCKET
,
USER_HEADER_IMG_PATH
)
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"接收返回值失败,%v"
,
err
),
gin
.
H
{})
}
else
{
...
...
QMPlusServer/controller/servers/upload.go
浏览文件 @
0e1d3867
...
...
@@ -13,7 +13,7 @@ var accessKey string = "25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ" // 你在七
var
secretKey
string
=
"pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY"
// 你在七牛云的secretKey 这里是我个人测试号的key 仅供测试使用 恳请大家不要乱传东西
// 接收两个参数 一个文件流 一个 bucket 你的七牛云标准空间的名字
func
Upload
(
file
*
multipart
.
FileHeader
,
bucket
string
,
urlPath
string
)
(
err
error
,
path
string
)
{
func
Upload
(
file
*
multipart
.
FileHeader
,
bucket
string
,
urlPath
string
)
(
err
error
,
path
string
,
key
string
)
{
putPolicy
:=
storage
.
PutPolicy
{
Scope
:
bucket
,
}
...
...
@@ -36,7 +36,7 @@ func Upload(file *multipart.FileHeader, bucket string, urlPath string) (err erro
f
,
e
:=
file
.
Open
()
if
e
!=
nil
{
fmt
.
Println
(
e
)
return
e
,
""
return
e
,
""
,
""
}
dataLen
:=
file
.
Size
fileKey
:=
fmt
.
Sprintf
(
"%d%s"
,
time
.
Now
()
.
Unix
(),
file
.
Filename
)
// 文件名格式 自己可以改 建议保证唯一性
...
...
@@ -44,7 +44,26 @@ func Upload(file *multipart.FileHeader, bucket string, urlPath string) (err erro
if
err
!=
nil
{
fmt
.
Println
(
err
)
//qmlog.QMLog.Info(err)
return
err
,
""
return
err
,
""
,
""
}
return
err
,
urlPath
+
"/"
+
ret
.
Key
return
err
,
urlPath
+
"/"
+
ret
.
Key
,
ret
.
Key
}
func
DeleteFile
(
bucket
string
,
key
string
)
error
{
mac
:=
qbox
.
NewMac
(
accessKey
,
secretKey
)
cfg
:=
storage
.
Config
{
// 是否使用https域名进行资源管理
UseHTTPS
:
false
,
}
// 指定空间所在的区域,如果不指定将自动探测
// 如果没有特殊需求,默认不需要指定
//cfg.Zone=&storage.ZoneHuabei
bucketManager
:=
storage
.
NewBucketManager
(
mac
,
&
cfg
)
err
:=
bucketManager
.
Delete
(
bucket
,
key
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
err
}
return
nil
}
QMPlusServer/docs/docs.go
浏览文件 @
0e1d3867
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-11-20 1
0:46:22.2795763 +0800 CST m=+0.0538962
01
// 2019-11-20 1
6:37:42.2606856 +0800 CST m=+0.0648250
01
package
docs
...
...
@@ -505,6 +505,42 @@ var doc = `{
}
}
},
"/fileUploadAndDownload/deleteFile": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"FileUploadAndDownload"
],
"summary": "删除文件",
"parameters": [
{
"description": "传入文件里面id即可",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/dbModel.FileUploadAndDownload"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"返回成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/fileUploadAndDownload/getFileList": {
"post": {
"security": [
...
...
@@ -1251,6 +1287,20 @@ var doc = `{
}
}
},
"dbModel.FileUploadAndDownload": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"tag": {
"type": "string"
},
"url": {
"type": "string"
}
}
},
"dbModel.Workflow": {
"type": "object",
"properties": {
...
...
@@ -1297,10 +1347,6 @@ var doc = `{
"stepNo": {
"description": "步骤id (第几步)",
"type": "number"
},
"workflowID": {
"description": "所属工作流ID",
"type": "integer"
}
}
},
...
...
QMPlusServer/docs/swagger.json
浏览文件 @
0e1d3867
...
...
@@ -488,6 +488,42 @@
}
}
},
"/fileUploadAndDownload/deleteFile"
:
{
"post"
:
{
"security"
:
[
{
"ApiKeyAuth"
:
[]
}
],
"produces"
:
[
"application/json"
],
"tags"
:
[
"FileUploadAndDownload"
],
"summary"
:
"删除文件"
,
"parameters"
:
[
{
"description"
:
"传入文件里面id即可"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/dbModel.FileUploadAndDownload"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
返回成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
}
}
}
},
"/fileUploadAndDownload/getFileList"
:
{
"post"
:
{
"security"
:
[
...
...
@@ -1234,6 +1270,20 @@
}
}
},
"dbModel.FileUploadAndDownload"
:
{
"type"
:
"object"
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
},
"tag"
:
{
"type"
:
"string"
},
"url"
:
{
"type"
:
"string"
}
}
},
"dbModel.Workflow"
:
{
"type"
:
"object"
,
"properties"
:
{
...
...
@@ -1280,10 +1330,6 @@
"stepNo"
:
{
"description"
:
"步骤id (第几步)"
,
"type"
:
"number"
},
"workflowID"
:
{
"description"
:
"所属工作流ID"
,
"type"
:
"integer"
}
}
},
...
...
QMPlusServer/docs/swagger.yaml
浏览文件 @
0e1d3867
...
...
@@ -112,6 +112,15 @@ definitions:
title
:
type
:
string
type
:
object
dbModel.FileUploadAndDownload
:
properties
:
name
:
type
:
string
tag
:
type
:
string
url
:
type
:
string
type
:
object
dbModel.Workflow
:
properties
:
workflowDescription
:
...
...
@@ -146,9 +155,6 @@ definitions:
stepNo
:
description
:
步骤id (第几步)
type
:
number
workflowID
:
description
:
所属工作流ID
type
:
integer
type
:
object
modelInterface.PageInfo
:
properties
:
...
...
@@ -460,6 +466,28 @@ paths:
summary
:
用户注册账号
tags
:
-
Base
/fileUploadAndDownload/deleteFile
:
post
:
parameters
:
-
description
:
传入文件里面id即可
in
:
body
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/dbModel.FileUploadAndDownload'
type
:
object
produces
:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"返回成功"}'
schema
:
type
:
string
security
:
-
ApiKeyAuth
:
[]
summary
:
删除文件
tags
:
-
FileUploadAndDownload
/fileUploadAndDownload/getFileList
:
post
:
consumes
:
...
...
QMPlusServer/model/dbModel/fileUploadAndDownload.go
浏览文件 @
0e1d3867
...
...
@@ -12,6 +12,7 @@ type FileUploadAndDownload struct {
Name
string
`json:"name"`
Url
string
`json:"url"`
Tag
string
`json:"tag"`
Key
string
`json:"key"`
}
func
(
f
*
FileUploadAndDownload
)
Upload
()
error
{
...
...
@@ -19,6 +20,17 @@ func (f *FileUploadAndDownload) Upload() error {
return
err
}
func
(
f
*
FileUploadAndDownload
)
DeleteFile
()
error
{
err
:=
qmsql
.
DEFAULTDB
.
Where
(
"id = ?"
,
f
.
ID
)
.
Delete
(
f
)
.
Error
return
err
}
func
(
f
*
FileUploadAndDownload
)
FindFile
()
(
error
,
FileUploadAndDownload
)
{
var
file
FileUploadAndDownload
err
:=
qmsql
.
DEFAULTDB
.
Where
(
"id = ?"
,
f
.
ID
)
.
First
(
&
file
)
.
Error
return
err
,
file
}
// 分页获取数据 需要分页实现这个接口即可
func
(
f
*
FileUploadAndDownload
)
GetInfoList
(
info
modelInterface
.
PageInfo
)
(
err
error
,
list
interface
{},
total
int
)
{
// 封装分页方法 调用即可 传入 当前的结构体和分页信息
...
...
QMPlusServer/router/fileUploadAndDownload.go
浏览文件 @
0e1d3867
...
...
@@ -3,13 +3,14 @@ package router
import
(
"github.com/gin-gonic/gin"
"main/controller/api"
"main/middleware"
)
func
InitFileUploadAndDownloadRouter
(
Router
*
gin
.
Engine
)
{
FileUploadAndDownloadGroup
:=
Router
.
Group
(
"fileUploadAndDownload"
)
.
Use
(
middleware
.
JWTAuth
())
FileUploadAndDownloadGroup
:=
Router
.
Group
(
"fileUploadAndDownload"
)
//.Use(middleware.JWTAuth())
{
FileUploadAndDownloadGroup
.
POST
(
"/upload"
,
api
.
UploadFile
)
// 上传文件
FileUploadAndDownloadGroup
.
POST
(
"/getFileList"
,
api
.
GetFileList
)
// 获取上传文件列表
FileUploadAndDownloadGroup
.
POST
(
"/deleteFile"
,
api
.
DeleteFile
)
// 删除指定文件
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录