first esitant check is needed

This commit is contained in:
gitGnome
2026-04-15 10:08:20 +02:00
parent fcda29a66b
commit 90018bccdd
2 changed files with 50 additions and 1 deletions
+41
View File
@@ -1,6 +1,10 @@
package http
import (
"crypto/sha256"
"go-socket/packages/globals"
"go-socket/packages/minio"
"io"
"net/http"
"go-socket/packages/convertions"
@@ -29,4 +33,41 @@ func HandleFileUpload(response http.ResponseWriter, request *http.Request) {
return
}
request.Body = http.MaxBytesReader(response, request.Body, int64(globals.MaxPostWithFileBytes))
multipartReader, err := request.MultipartReader()
if err != nil {
http.Error(response, "expected multipart form", 400)
return
}
for {
part, err := multipartReader.NextPart()
if err == io.EOF {
http.Error(response, "bad request", 400)
return
}
if part.FileName() == "" {
part.Close()
continue
}
if len(part.FileName()) != sha256.Size {
part.Close()
http.Error(response, "filename must be sha256 of whole file", 400)
return
}
err = minio.Upload(ctx, part.FileName(), part, -1, part.Header.Get("Content-Type"), user.Id)
if err != nil {
http.Error(response, "upload failed", http.StatusInternalServerError)
return
}
part.Close()
if err != nil {
http.Error(response, "upload failed", 500)
return
}
}
}