Skip to content

Commit

Permalink
feat: ensure parent directories exist before file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
PlusOne committed Jan 26, 2025
1 parent b1da464 commit 3490c2f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,14 @@ func handleUpload(w http.ResponseWriter, r *http.Request, absFilename, fileStore
return
}

// Ensure the parent directories exist
err = os.MkdirAll(filepath.Dir(finalFilename), 0755)
if err != nil {
log.WithError(err).Errorf("Failed to create directory for file %s", finalFilename)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}

// Move temp file to final destination
err = os.Rename(tempFilename, finalFilename)
if err != nil {
Expand Down

0 comments on commit 3490c2f

Please sign in to comment.