From 6c864612db48148308e879aba9c9b089e0802686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Sat, 10 Jan 2026 21:11:53 +0100 Subject: [PATCH] Add comprehensive upload/download debugging to fix file storage issues --- go_cloud/internal/http/routes.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go_cloud/internal/http/routes.go b/go_cloud/internal/http/routes.go index 7135e87..69d639f 100644 --- a/go_cloud/internal/http/routes.go +++ b/go_cloud/internal/http/routes.go @@ -1247,9 +1247,11 @@ func createUserFileHandler(w http.ResponseWriter, r *http.Request, db *database. storedPath = "/" + storedPath } written := int64(len(data)) + fmt.Printf("[DEBUG] Upload: user=%s, file=%s, size=%d, path=%s\n", userID.String(), header.Filename, len(data), storedPath) if storageClient != nil { rel := strings.TrimPrefix(storedPath, "/") remotePath := path.Join("/users", userID.String(), rel) + fmt.Printf("[DEBUG] Uploading to WebDAV: %s\n", remotePath) if err = storageClient.Upload(r.Context(), remotePath, bytes.NewReader(data), int64(len(data))); err != nil { errors.LogError(r, err, "WebDAV upload failed, falling back to local disk") } else { @@ -1273,19 +1275,24 @@ func createUserFileHandler(w http.ResponseWriter, r *http.Request, db *database. } // Fallback: write to temp directory (WebDAV should be the primary storage) + fmt.Printf("[DEBUG] WebDAV is nil or failed, using local storage fallback\n") baseDir := filepath.Join("/tmp", "uploads", "users", userID.String()) targetDir := filepath.Join(baseDir, parentPath) + fmt.Printf("[DEBUG] Creating directory: %s\n", targetDir) if err = os.MkdirAll(targetDir, 0o755); err != nil { errors.LogError(r, err, "Failed to create target dir in /tmp") errors.WriteError(w, errors.CodeInternal, "Server error", http.StatusInternalServerError) return } outPath := filepath.Join(targetDir, header.Filename) + fmt.Printf("[DEBUG] Writing file to: %s\n", outPath) if err = os.WriteFile(outPath, data, 0o644); err != nil { + fmt.Printf("[DEBUG] Failed to write file: %v\n", err) errors.LogError(r, err, "Failed to write file to /tmp") errors.WriteError(w, errors.CodeInternal, "Server error", http.StatusInternalServerError) return } + fmt.Printf("[DEBUG] File written successfully to local storage: %s\n", outPath) f, err = db.CreateFile(r.Context(), nil, &userID, header.Filename, storedPath, "file", written) if err != nil {