package app import ( "io" "log/slog" filesengine "git.optclblast.xyz/draincloud/draincloud-core/internal/files_engine" "git.optclblast.xyz/draincloud/draincloud-core/internal/logger" "github.com/davecgh/go-spew/spew" "github.com/gin-gonic/gin" ) const ( maxFileSize = 10 << 30 ) func (d *DrainCloud) UploadFile(ctx *gin.Context) { if err := ctx.Request.ParseMultipartForm(maxFileSize); err != nil { logger.Error(ctx, "uploadFile handler error", logger.Err(err)) writeError(ctx, err) return } if err := d.uploadFile(ctx); err != nil { logger.Error(ctx, "uploadFile handle", logger.Err(err)) writeError(ctx, err) return } } func (d *DrainCloud) uploadFile(ctx *gin.Context) error { title := ctx.PostForm("file") logger.Info(ctx, "uploadFile", slog.Any("postForm data", spew.Sdump(title))) file, header, err := ctx.Request.FormFile("file") if err != nil { return err } logger.Info(ctx, "uploadFile", slog.Any("header", spew.Sdump(header))) data, err := io.ReadAll(file) if err != nil { return err } d.filesEngine.SaveFile(ctx, filesengine.File{ Name: header.Filename, // UserID: , }) return nil }