MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / UploadFileHandler

Function UploadFileHandler

daemon/pkg/handler/file_handler.go:113–147  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

111}
112
113func UploadFileHandler(ctx *gin.Context) {
114 // 单文件
115 relativePath := ctx.Query("path")
116 file, err := ctx.FormFile("file")
117 if err != nil {
118 errMsg := fmt.Sprintf("Get Upload File Error :%s", err.Error())
119 logrus.Error(errMsg)
120 resp := ginmodel.JsonResp{
121 Code: -1,
122 Message: errMsg,
123 Data: nil,
124 }
125 ctx.JSON(http.StatusBadRequest, resp)
126 return
127 }
128 dst := path.Join(dir.UserDataDir, relativePath, file.Filename)
129 err = ctx.SaveUploadedFile(file, dst)
130 if err != nil {
131 errMsg := fmt.Sprintf("Save Upload File %s Error :%s", file.Filename, err.Error())
132 logrus.Error(errMsg)
133 resp := ginmodel.JsonResp{
134 Code: -1,
135 Message: errMsg,
136 Data: nil,
137 }
138 ctx.JSON(http.StatusInternalServerError, resp)
139 return
140 }
141 resp := ginmodel.JsonResp{
142 Code: 0,
143 Message: "Success",
144 Data: nil,
145 }
146 ctx.JSON(http.StatusOK, resp)
147}
148
149func DeleteFileHandler(ctx *gin.Context) {
150 relativePath := ctx.Query("path")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected