Skip to content

Commit

Permalink
添加测试上传文件方法
Browse files Browse the repository at this point in the history
  • Loading branch information
wxluoyouda committed Mar 9, 2023
1 parent 91ab778 commit a82dd24
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/v1/fileserver/file/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.inferGopath": false
}
1 change: 1 addition & 0 deletions api/v1/fileserver/file/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adjlkfalkjflkadjfl`
21 changes: 21 additions & 0 deletions api/v1/fileserver/file_server.go
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
package fileserver

import (
"fmt"
"log"
"net/http"

"github.com/gin-gonic/gin"
)

// UploadFile 上传文件
func UploadFile(ctx *gin.Context) {
// 单文件
file, _ := ctx.FormFile("file")
log.Println(file.Filename)

dst := "./api/v1/fileserver/file/" + file.Filename
// 上传文件至指定的完整文件路径
ctx.SaveUploadedFile(file, dst)

ctx.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
}
20 changes: 20 additions & 0 deletions doc/设计.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,23 @@
-- Grpc服务
@endmindmap
```

```mermaid
flowchart LR
bychat
bychat --> 建立socket链接
建立socket链接 --> 心跳检测
建立socket链接 --> 重连
建立socket链接 --> 分布式通信
建立socket链接 --> 单聊,群聊
建立socket链接 --> 消息重复检查
bychat --> HTTP链接
HTTP链接 --> 登陆
HTTP链接 --> 退出
HTTP链接 --> 进入房间
HTTP链接 --> 退出房间
HTTP链接 --> 获取历史消息
HTTP链接 --> 发送通话消息
HTTP链接 --> 获取系统信息
HTTP链接 --> 发送文本,图片,视频,音频,文件,信息
```
7 changes: 7 additions & 0 deletions internal/routers/web_routers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package routers

import (
"bychat/api/v1/fileserver"
"bychat/api/v1/home"
"bychat/api/v1/systems"
"bychat/api/v1/user"
Expand Down Expand Up @@ -37,4 +38,10 @@ func InitWeb(router *gin.Engine) {
{
homeRouter.GET("/index", home.Index)
}
// file
file := router.Group("/upload")
router.MaxMultipartMemory = 8 << 20 // 8 MiB
{
file.POST("/file", fileserver.UploadFile)
}
}
20 changes: 20 additions & 0 deletions test/curl_20230309174915_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"config": {
"name": "testcase converted from curl command"
},
"teststeps": [
{
"name": "curl -X \"POST\" \"http://localhost:8080/upload/file\" -F \"file=@./text.txt\" -H \"Content-Type: multipart/form-data\"",
"request": {
"method": "POST",
"url": "http://localhost:8080/upload/file",
"headers": {
"Content-Type": "multipart/form-data"
},
"upload": {
"file": "@./text.txt"
}
}
}
]
}
3 changes: 3 additions & 0 deletions test/http.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl -X POST http: //localhost:8080/upload/file \
-F "file=@./text.txt" \
-H "Content-Type: multipart/form-data"

0 comments on commit a82dd24

Please sign in to comment.