package server import ( "encoding/json" "io" "log" "net/http" ) // handleUpload handles file uploads to ir.attachment. func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } // Parse multipart form (max 128MB) if err := r.ParseMultipartForm(128 << 20); err != nil { http.Error(w, "File too large", http.StatusRequestEntityTooLarge) return } file, header, err := r.FormFile("ufile") if err != nil { http.Error(w, "No file uploaded", http.StatusBadRequest) return } defer file.Close() // Read file content data, err := io.ReadAll(file) if err != nil { http.Error(w, "Read error", http.StatusInternalServerError) return } log.Printf("upload: received %s (%d bytes, %s)", header.Filename, len(data), header.Header.Get("Content-Type")) // TODO: Store in ir.attachment table or filesystem // For now, just acknowledge receipt w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]interface{}{ "id": 1, "name": header.Filename, "size": len(data), }) }