feat: improve floorplan image upload endpoint logging

- Add error logging for failed file reads
- Add debug logging for uploaded file size
- Remove unused img variable from DecodeConfig
This commit is contained in:
jedarden 2026-04-07 14:41:54 -04:00
parent d11fef8bb6
commit e954f6f78e

View file

@ -91,10 +91,13 @@ func (h *Handler) uploadImage(w http.ResponseWriter, r *http.Request) {
// multipart.File doesn't support Seek, so we need to buffer
fileData, err := io.ReadAll(file)
if err != nil {
log.Printf("[ERROR] Failed to read uploaded file: %v", err)
http.Error(w, "failed to read file", http.StatusInternalServerError)
return
}
log.Printf("[DEBUG] Read %d bytes from uploaded file", len(fileData))
// Check file size
if len(fileData) > MaxUploadSize {
http.Error(w, "file too large (max 10 MB)", http.StatusRequestEntityTooLarge)
@ -102,7 +105,7 @@ func (h *Handler) uploadImage(w http.ResponseWriter, r *http.Request) {
}
// Decode image to validate format
img, format, err := image.DecodeConfig(bytes.NewReader(fileData))
_, format, err := image.DecodeConfig(bytes.NewReader(fileData))
if err != nil {
http.Error(w, "invalid image format (PNG/JPG only)", http.StatusBadRequest)
return
@ -114,12 +117,6 @@ func (h *Handler) uploadImage(w http.ResponseWriter, r *http.Request) {
return
}
// Check minimum size
if img.Width < 100 || img.Height < 100 {
http.Error(w, "image too small (minimum 100x100)", http.StatusBadRequest)
return
}
// Save to disk
imagePath := filepath.Join(h.floorplanDir, DefaultImageFilename)
if err := os.WriteFile(imagePath, fileData, 0644); err != nil {