diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index b873b51..cf4b41b 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -133,16 +133,14 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusInternalServerError) return } + defer fDst.Close() - n, err := io.Copy(fDst, f) + _, err = io.Copy(fDst, f) if err != nil { h.logErr.Println("failed to copy uploaded file to destination:", err) w.WriteHeader(http.StatusInternalServerError) return } - fmt.Println(n, err) - fDst.Sync() - fDst.Close() h.logUpload.Printf("| %s | %s | %s | SHA256 %s | %s | %d", r.RemoteAddr, utils.NetworkType(r.Host), fHandler.Filename, fSha256, fSaltedHash, fHandler.Size) @@ -150,6 +148,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusCreated) } else { os.Chtimes(fPath, time.Now(), time.Now()) + w.WriteHeader(http.StatusFound) } downloadURL := path.Join("/f", fSaltedHash, fHandler.Filename)