Add comprehensive upload/download debugging to fix file storage issues

This commit is contained in:
Leon Bösche
2026-01-10 21:11:53 +01:00
parent 288363d2da
commit 6c864612db

View File

@@ -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 {