Skip to content

Commit 65c0fe9

Browse files
authored
Committed the example project.
1 parent 55b1ae9 commit 65c0fe9

File tree

86 files changed

+74634
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+74634
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using Microsoft.AspNetCore.Http.Features;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Diagnostics;
4+
5+
namespace SyncfusionUploaderServerApp.Controllers
6+
{
7+
public class HomeController : Controller
8+
{
9+
private readonly string _uploads = Path.Combine(Directory.GetCurrentDirectory(), "Uploaded Files");
10+
11+
public async Task<IActionResult> Save(IFormFile UploadFiles)
12+
{
13+
if (!IsAuthorized())
14+
{
15+
return Unauthorized();
16+
}
17+
18+
if (UploadFiles == null || UploadFiles.Length == 0)
19+
{
20+
return BadRequest("Invalid file.");
21+
}
22+
23+
Directory.CreateDirectory(_uploads);
24+
25+
var filePath = Path.Combine(_uploads, UploadFiles.FileName);
26+
var append = UploadFiles.ContentType == "application/octet-stream"; // Handle chunk upload
27+
await SaveFileAsync(UploadFiles, filePath, append);
28+
29+
return Ok();
30+
}
31+
32+
private bool IsAuthorized()
33+
{
34+
var authorizationHeader = Request.Headers["Authorization"].ToString();
35+
if(string.IsNullOrEmpty(authorizationHeader) ||
36+
!authorizationHeader.StartsWith("Bearer "))
37+
{
38+
return false;
39+
}
40+
var token = authorizationHeader["Bearer ".Length..];
41+
return token == "Your.JWT.Token";
42+
}
43+
44+
private async Task SaveFileAsync(IFormFile file, string path, bool append)
45+
{
46+
await using var fileStream = new FileStream(path, append ? FileMode.Append : FileMode.Create);
47+
await file.CopyToAsync(fileStream);
48+
}
49+
50+
public IActionResult Remove(string UploadFiles)
51+
{
52+
if(!IsAuthorized())
53+
{
54+
return Unauthorized();
55+
}
56+
57+
try
58+
{
59+
var filePath = Path.Combine(_uploads, UploadFiles);
60+
if (System.IO.File.Exists(filePath))
61+
{
62+
System.IO.File.Delete(filePath);
63+
Response.StatusCode = 200;
64+
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File removed successfully";
65+
}
66+
else
67+
{
68+
Response.StatusCode = 404;
69+
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File not found";
70+
}
71+
}
72+
catch (Exception e)
73+
{
74+
Response.StatusCode = 500;
75+
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = $"Error: {e.Message}";
76+
}
77+
78+
return new EmptyResult();
79+
}
80+
81+
public IActionResult Index()
82+
{
83+
return View();
84+
}
85+
}
86+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
//Register Syncfusion license https://help.syncfusion.com/common/essential-studio/licensing/how-to-generate
3+
//Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("YOUR LICENSE KEY");
4+
5+
// Add services to the container.
6+
builder.Services.AddControllersWithViews();
7+
8+
builder.Services.AddCors(options =>
9+
{
10+
options.AddPolicy("EnableCORS", builder =>
11+
{
12+
builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
13+
});
14+
});
15+
16+
var app = builder.Build();
17+
18+
// Configure the HTTP request pipeline.
19+
if (!app.Environment.IsDevelopment())
20+
{
21+
app.UseExceptionHandler("/Home/Error");
22+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
23+
app.UseHsts();
24+
}
25+
26+
app.UseHttpsRedirection();
27+
app.UseStaticFiles();
28+
29+
app.UseRouting();
30+
app.UseCors("EnableCORS");
31+
app.UseAuthorization();
32+
33+
app.MapControllerRoute(
34+
name: "default",
35+
pattern: "{controller=Home}/{action=Index}/{id?}");
36+
37+
app.Run();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:16892",
8+
"sslPort": 44329
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5278",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7113;http://localhost:5278",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.10.35004.147
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SyncfusionUploaderServerApp", "SyncfusionUploaderServerApp.csproj", "{319A35CC-6F29-443C-A1D9-936E7A804F9B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{319A35CC-6F29-443C-A1D9-936E7A804F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{319A35CC-6F29-443C-A1D9-936E7A804F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{319A35CC-6F29-443C-A1D9-936E7A804F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{319A35CC-6F29-443C-A1D9-936E7A804F9B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1A02C880-9BA8-4C0E-93E8-CDA6D27309C9}
24+
EndGlobalSection
25+
EndGlobal
10.6 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
<h1>Server Started!</h1>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Syncfusion Uploader Server App</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
</head>
10+
<body>
11+
<header>
12+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
13+
<div class="container-fluid">
14+
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Syncfusion Uploader Server App</a>
15+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
16+
aria-expanded="false" aria-label="Toggle navigation">
17+
<span class="navbar-toggler-icon"></span>
18+
</button>
19+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
20+
<ul class="navbar-nav flex-grow-1">
21+
<li class="nav-item">
22+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
23+
</li>
24+
<li class="nav-item">
25+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
26+
</li>
27+
</ul>
28+
</div>
29+
</div>
30+
</nav>
31+
</header>
32+
<div class="container">
33+
<main role="main" class="pb-3">
34+
@RenderBody()
35+
</main>
36+
</div>
37+
38+
<footer class="border-top footer text-muted">
39+
<div class="container">
40+
&copy; 2024 - Syncfusion Uploader Server App - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
41+
</div>
42+
</footer>
43+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
44+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
45+
<script src="~/js/site.js" asp-append-version="true"></script>
46+
@await RenderSectionAsync("Scripts", required: false)
47+
</body>
48+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
a {
11+
color: #0077cc;
12+
}
13+
14+
.btn-primary {
15+
color: #fff;
16+
background-color: #1b6ec2;
17+
border-color: #1861ac;
18+
}
19+
20+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21+
color: #fff;
22+
background-color: #1b6ec2;
23+
border-color: #1861ac;
24+
}
25+
26+
.border-top {
27+
border-top: 1px solid #e5e5e5;
28+
}
29+
.border-bottom {
30+
border-bottom: 1px solid #e5e5e5;
31+
}
32+
33+
.box-shadow {
34+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35+
}
36+
37+
button.accept-policy {
38+
font-size: 1rem;
39+
line-height: inherit;
40+
}
41+
42+
.footer {
43+
position: absolute;
44+
bottom: 0;
45+
width: 100%;
46+
white-space: nowrap;
47+
line-height: 60px;
48+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
2+
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

0 commit comments

Comments
 (0)