MCPcopy Index your code
hub / github.com/53AI/53AIHub / serveUploadFile

Function serveUploadFile

api/controller/message.go:924–941  ·  view source on GitHub ↗
(c *gin.Context, file *model.UploadFile)

Source from the content-addressed store, hash-verified

922}
923
924func serveUploadFile(c *gin.Context, file *model.UploadFile) {
925 content, err := storage.StorageInstance.Load(file.Key)
926 if err != nil {
927 logger.Errorf(c.Request.Context(), "Failed to read file %s: %v", file.Key, err)
928 c.JSON(http.StatusInternalServerError, model.SystemError.ToResponse(err))
929 return
930 }
931
932 // 设置下载头
933 downloadName := path.Base(strings.TrimSpace(file.FileName))
934 if downloadName == "" || downloadName == "." || downloadName == "/" {
935 downloadName = "download.bin"
936 }
937 c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", downloadName))
938 c.Header("Content-Type", file.MimeType)
939 c.Header("Content-Length", strconv.FormatInt(file.Size, 10))
940 c.Data(http.StatusOK, file.MimeType, content)
941}

Callers 1

DownloadAIUploadFileFunction · 0.85

Calls 4

ErrorfMethod · 0.80
ToResponseMethod · 0.80
LoadMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected