|
11 | 11 | @inject ILogger<FileManager> Logger; |
12 | 12 | @inject NavigationManager NavManager |
13 | 13 |
|
14 | | -@* Loading while detecting viewport *@ |
15 | | -@if (!_viewportDetected) |
| 14 | +@* Loading while detecting viewport and base URL *@ |
| 15 | +@if (!_viewportDetected || string.IsNullOrEmpty(_baseUrl)) |
16 | 16 | { |
17 | 17 | <div style="display: flex; justify-content: center; align-items: center; height: 200px;"> |
18 | 18 | <div class="spinner-border text-primary" role="status"> |
|
21 | 21 | </div> |
22 | 22 | } |
23 | 23 |
|
24 | | -@* Desktop FileManager - only render when viewport detected and not on mobile *@ |
25 | | -@if (_viewportDetected && !_isMobileView) |
| 24 | +@* Desktop FileManager - only render when viewport detected, base URL ready, and not on mobile *@ |
| 25 | +@if (_viewportDetected && !string.IsNullOrEmpty(_baseUrl) && !_isMobileView) |
26 | 26 | { |
27 | 27 | <SfFileManager @ref="FileManager" ID="localfm" TValue="FileManagerDirectoryContent"> |
28 | 28 | <FileManagerAjaxSettings Url="@FileOperationsUrl" |
|
39 | 39 | } |
40 | 40 |
|
41 | 41 | @* Mobile FileManager *@ |
42 | | -@if (_viewportDetected && _isMobileView) |
| 42 | +@if (_viewportDetected && !string.IsNullOrEmpty(_baseUrl) && _isMobileView) |
43 | 43 | { |
44 | 44 | <div class="mobile-fm-container"> |
45 | 45 | <MobileFileManager @ref="mobileFileManager" |
|
101 | 101 | private bool _viewportDetected = false; |
102 | 102 | private const int MobileBreakpoint = 1920; // Custom breakpoint for mobile file manager |
103 | 103 |
|
104 | | - // Use NavigationManager.BaseUri to build absolute URLs that work with both direct access and reverse proxies |
105 | | - private string FileOperationsUrl => $"{NavManager.BaseUri}api/file/FileOperations"; |
106 | | - private string UploadUrl => $"{NavManager.BaseUri}api/file/Upload"; |
107 | | - private string DownloadUrl => $"{NavManager.BaseUri}api/file/Download"; |
108 | | - private string GetImageUrl => $"{NavManager.BaseUri}api/file/GetImage"; |
| 104 | + // URLs will be set from JavaScript to get the actual browser origin |
| 105 | + private string _baseUrl = ""; |
| 106 | + private string FileOperationsUrl => $"{_baseUrl}/api/file/FileOperations"; |
| 107 | + private string UploadUrl => $"{_baseUrl}/api/file/Upload"; |
| 108 | + private string DownloadUrl => $"{_baseUrl}/api/file/Download"; |
| 109 | + private string GetImageUrl => $"{_baseUrl}/api/file/GetImage"; |
109 | 110 |
|
110 | 111 |
|
111 | 112 | public List<ToolBarItemModel> Items = new List<ToolBarItemModel>(){ |
|
150 | 151 | { |
151 | 152 | _firstRenderComplete = true; |
152 | 153 | _currentInstance = this; |
| 154 | + |
| 155 | + // Get actual browser origin via JavaScript (works correctly with reverse proxies) |
| 156 | + _baseUrl = await JSRuntime.InvokeAsync<string>("eval", "window.location.origin"); |
| 157 | + Logger.LogInformation($"LocalFileManager BaseUrl: {_baseUrl}"); |
| 158 | + |
153 | 159 | // Detect viewport size on first render |
154 | 160 | await DetectMobileView(); |
| 161 | + |
| 162 | + // Force re-render to apply the URLs |
| 163 | + StateHasChanged(); |
155 | 164 | } |
156 | 165 |
|
157 | 166 | if (_needsRefresh && FileManager != null) |
|
0 commit comments