(c *gin.Context, file *model.UploadFile)
| 922 | } |
| 923 | |
| 924 | func 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 | } |
no test coverage detected