diff --git a/.vs/ProjectEvaluation/a4paperholder.metadata.v9.bin b/.vs/ProjectEvaluation/a4paperholder.metadata.v9.bin new file mode 100644 index 0000000..ee15b19 Binary files /dev/null and b/.vs/ProjectEvaluation/a4paperholder.metadata.v9.bin differ diff --git a/.vs/ProjectEvaluation/a4paperholder.projects.v9.bin b/.vs/ProjectEvaluation/a4paperholder.projects.v9.bin new file mode 100644 index 0000000..6a82d6d Binary files /dev/null and b/.vs/ProjectEvaluation/a4paperholder.projects.v9.bin differ diff --git a/.vs/ProjectEvaluation/a4paperholder.strings.v9.bin b/.vs/ProjectEvaluation/a4paperholder.strings.v9.bin new file mode 100644 index 0000000..146a44d Binary files /dev/null and b/.vs/ProjectEvaluation/a4paperholder.strings.v9.bin differ diff --git a/a4PaperHolder.sln b/a4PaperHolder.sln index 9e6e831..5bd8318 100644 --- a/a4PaperHolder.sln +++ b/a4PaperHolder.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.13.35931.197 d17.13 +VisualStudioVersion = 17.13.35931.197 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "a4PaperHolder", "a4PaperHolder\a4PaperHolder.csproj", "{95F1076B-0572-4793-88E2-40D16276519D}" EndProject diff --git a/a4PaperHolder/Pages/Index.cshtml b/a4PaperHolder/Pages/Index.cshtml index ea8b557..78e3fb5 100644 --- a/a4PaperHolder/Pages/Index.cshtml +++ b/a4PaperHolder/Pages/Index.cshtml @@ -33,4 +33,6 @@ } - \ No newline at end of file + + +파일 업로드 diff --git a/a4PaperHolder/Pages/Upload.cshtml b/a4PaperHolder/Pages/Upload.cshtml new file mode 100644 index 0000000..d24c1fd --- /dev/null +++ b/a4PaperHolder/Pages/Upload.cshtml @@ -0,0 +1,17 @@ +@page +@model a4PaperHolder.Pages.UploadModel +@{ + ViewData["Title"] = "파일 업로드"; +} + +

파일 업로드

+ +
+ + +
+ +@if (Model.Message != null) +{ +

@Model.Message

+} \ No newline at end of file diff --git a/a4PaperHolder/Pages/Upload.cshtml.cs b/a4PaperHolder/Pages/Upload.cshtml.cs new file mode 100644 index 0000000..6dd8475 --- /dev/null +++ b/a4PaperHolder/Pages/Upload.cshtml.cs @@ -0,0 +1,37 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace a4PaperHolder.Pages; + +public class UploadModel : PageModel +{ + [BindProperty] + public IFormFile? UploadFile { get; set; } + + public string? Message { get; set; } + + public void OnGet() { } + + public async Task OnPostAsync() + { + Console.WriteLine("onpostcalled"); + if (UploadFile == null || UploadFile.Length == 0) + { + Message = " ּ."; + return Page(); + } + + var basePath = Path.Combine(AppContext.BaseDirectory, "NASFiles"); + + if (!Directory.Exists(basePath)) + Directory.CreateDirectory(basePath); + + var filePath = Path.Combine(basePath, Path.GetFileName(UploadFile.FileName)); + + await using var stream = System.IO.File.Create(filePath); + await UploadFile.CopyToAsync(stream); + + Message = "ε Ϸ!"; + return Page(); + } +} diff --git a/a4PaperHolder/Program.cs b/a4PaperHolder/Program.cs index 1669785..a8a290b 100644 --- a/a4PaperHolder/Program.cs +++ b/a4PaperHolder/Program.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.StaticFiles; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.StaticFiles; using System.Text; var builder = WebApplication.CreateBuilder(args); @@ -9,6 +10,12 @@ var app = builder.Build(); //razor가 브라우저에서 돌아가면? brazor 작명센스 조졌네 app.UseStaticFiles(); + +//MvcOptions mvcOption = new(); +//mvcOption.EnableEndpointRouting = false; +app.UseRouting(); +app.UseAuthorization(); +//app.UseMvc(); app.MapRazorPages(); var basePath = Path.Combine(AppContext.BaseDirectory, "NASFiles"); @@ -30,7 +37,17 @@ app.MapGet("/view", (HttpRequest request) => provider.TryGetContentType(filePath, out var contentType); contentType ??= "application/octet-stream"; - return Results.File(System.IO.File.OpenRead(filePath), contentType); + var stream = System.IO.File.OpenRead(filePath); + + //플레인텍스트같은 확장자는 그냥 다운로드되버리는 문제 있음 일단 영상유형 확장자의 앞으로감기,뒤로감기 처리는 됨 + //return Results.Stream( + // stream, + // contentType, + // fileDownloadName: fileName, + // enableRangeProcessing: true + // ); + + return Results.File(System.IO.File.OpenRead(filePath), contentType); }); app.Run();