Skip to content

Commit 6d149fd

Browse files
authored
Merge pull request #4 from sivakumars3442/master
946893: Updated the sample with latest feature in file manager component.
2 parents 3665835 + 220b593 commit 6d149fd

File tree

6 files changed

+49
-31
lines changed

6 files changed

+49
-31
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<RootNamespace>ASPCore_FileManager_WebAPI</RootNamespace>
88
</PropertyGroup>
99
<ItemGroup>
10-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
11-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.26" />
12-
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.35.0" />
13-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.35.0" />
10+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
11+
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.6.1" />
12+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.6.1" />
1413
</ItemGroup>
1514
</Project>

ASPCore-FileManager-WebAPI/ASPCore-FileManager-WebAPI/Controllers/FileManagerController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Syncfusion.EJ2.FileManager.PhysicalFileProvider;
44
using Syncfusion.EJ2.FileManager.Base;
55
using Microsoft.AspNetCore.Cors;
6-
using Newtonsoft.Json;
6+
using System.Text.Json;
77
using System.IO;
88
using Microsoft.AspNetCore.Authorization;
99
using System.Data;
@@ -18,7 +18,6 @@ public class FileManagerController : Controller
1818
string basePath;
1919
string root = "wwwroot\\Files";
2020

21-
[Obsolete]
2221
public FileManagerController(IWebHostEnvironment hostingEnvironment)
2322
{
2423
this.basePath = hostingEnvironment.ContentRootPath;
@@ -95,6 +94,7 @@ public object FileOperations([FromBody] FileManagerDirectoryContent args)
9594
/// <returns></returns>
9695
//[HttpPost]
9796
[Route("Upload")]
97+
[Authorize(Roles = "Admin")]
9898
public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string action)
9999
{
100100
FileManagerResponse uploadResponse;
@@ -132,9 +132,9 @@ public IActionResult Upload(string path, IList<IFormFile> uploadFiles, string ac
132132
/// <returns></returns>
133133
//[HttpPost]
134134
[Route("Download")]
135-
public IActionResult Download(string downloadInput)
135+
[Authorize(Roles = "Admin")]
136+
public IActionResult Download([FromBody] FileManagerDirectoryContent args)
136137
{
137-
FileManagerDirectoryContent args = JsonConvert.DeserializeObject<FileManagerDirectoryContent>(downloadInput);
138138
return operation.Download(args.Path, args.Names, args.Data);
139139
}
140140

@@ -145,7 +145,8 @@ public IActionResult Download(string downloadInput)
145145
/// <returns></returns>
146146
//[HttpGet]
147147
[Route("GetImage")]
148-
public IActionResult GetImage(FileManagerDirectoryContent args)
148+
[Authorize(Roles = "Admin")]
149+
public IActionResult GetImage([FromBody] FileManagerDirectoryContent args)
149150
{
150151
return this.operation.GetImage(args.Path, args.Id, false, null, null);
151152
}

ASPCore-FileManager-WebAPI/ASPCore-FileManager-WebAPI/Models/Base/FileProviderBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Serialization;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
53
using System.IO;
64
using System.IO.Compression;

ASPCore-FileManager-WebAPI/ASPCore-FileManager-WebAPI/Models/PhysicalFileProvider.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Serialization;
1+
using System.Text.Json;
32
using System;
43
using System.Collections.Generic;
54
using System.IO;
@@ -2152,18 +2151,12 @@ protected virtual bool parentsHavePermission(FileManagerDirectoryContent fileDet
21522151
}
21532152
public string ToCamelCase(FileManagerResponse userData)
21542153
{
2155-
return JsonConvert.SerializeObject(userData, new JsonSerializerSettings
2154+
JsonSerializerOptions options = new JsonSerializerOptions
21562155
{
2157-
#if EJ2_DNX
2158-
ContractResolver = new CamelCasePropertyNamesContractResolver()
2156+
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
2157+
};
21592158

2160-
#else
2161-
ContractResolver = new DefaultContractResolver
2162-
{
2163-
NamingStrategy = new CamelCaseNamingStrategy()
2164-
}
2165-
#endif
2166-
});
2159+
return JsonSerializer.Serialize(userData, options);
21672160
}
21682161

21692162
FileStreamResult FileProviderBase.Download(string path, string[] names, params FileManagerDirectoryContent[] data)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<RootNamespace>Blazor_FileManager_Client</RootNamespace>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.20" />
12-
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.26" />
13-
<PackageReference Include="Syncfusion.Blazor.FileManager" Version="22.2.7" />
14-
<PackageReference Include="Syncfusion.Blazor.Themes" Version="22.2.7" />
11+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="9.0.3" />
12+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
13+
<PackageReference Include="Syncfusion.Blazor.FileManager" Version="*" />
14+
<PackageReference Include="Syncfusion.Blazor.Themes" Version="*" />
1515
</ItemGroup>
1616

1717
</Project>

Blazor-FileManager-Client/Blazor-FileManager-Client/Pages/Index.razor

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
UploadUrl="https://localhost:7073/api/FileManager/Upload"
1313
DownloadUrl="https://localhost:7073/api/FileManager/Download"
1414
GetImageUrl="https://localhost:7073/api/FileManager/GetImage"></FileManagerAjaxSettings>
15-
<FileManagerEvents TValue="FileManagerDirectoryContent" OnSend="OnBeforeSend"></FileManagerEvents>
15+
<FileManagerUploadSettings UploadMode="UploadMode.HttpClient"></FileManagerUploadSettings>
16+
<FileManagerEvents TValue="FileManagerDirectoryContent" OnSend="OnBeforeSend" BeforeImageLoad="HandleBeforeImageLoad" BeforeDownload="HandleBeforeDownload"></FileManagerEvents>
1617
</SfFileManager>
1718
@code {
1819
[CascadingParameter]
@@ -71,5 +72,31 @@
7172
args.HttpClientInstance.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
7273
isRead = false;
7374
}
75+
76+
if (args.Action == "Upload")
77+
{
78+
args.HttpClientInstance.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
79+
}
80+
}
81+
82+
private void HandleBeforeImageLoad(BeforeImageLoadEventArgs<FileManagerDirectoryContent> args)
83+
{
84+
// Switch to HTTP Client-based approach
85+
args.UseImageAsUrl = false;
86+
87+
// Add JWT token for image requests
88+
args.HttpClientInstance.DefaultRequestHeaders.Authorization =
89+
new AuthenticationHeaderValue("Bearer", Token);
90+
}
91+
92+
// Handle download operations
93+
private void HandleBeforeDownload(BeforeDownloadEventArgs<FileManagerDirectoryContent> args)
94+
{
95+
// Switch to HTTP Client-based approach
96+
args.UseFormPost = false;
97+
98+
// Add JWT token for download requests
99+
args.HttpClientInstance.DefaultRequestHeaders.Authorization =
100+
new AuthenticationHeaderValue("Bearer", Token);
74101
}
75102
}

0 commit comments

Comments
 (0)