From: joinsang Date: Sat, 23 Feb 2019 05:42:24 +0000 (+0900) Subject: 서버단 파일업로드 기능 추가 X-Git-Url: https://git.insang.kr/gitweb/?a=commitdiff_plain;h=56c5d685e626f4a2d440e6c4bddaa17c144c09ce;p=ZipProject.git 서버단 파일업로드 기능 추가 코드작성후 테스트는 안해봄 안될수도 --- diff --git a/ZipProject/Controllers/WebZipController.cs b/ZipProject/Controllers/WebZipController.cs index 84d4b2a..8228ce1 100644 --- a/ZipProject/Controllers/WebZipController.cs +++ b/ZipProject/Controllers/WebZipController.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using ZipProject.Models; +using Newtonsoft.Json.Linq; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -46,6 +47,14 @@ namespace ZipProject.Controllers { return Redirect ("/"); } + public JsonResult FileUpload(List dirList, List files, string fileKeyPair){ + JObject keyPair_FileDir= JObject.Parse(fileKeyPair); + + ZipModel zipModel= new ZipModel(); + zipModel.SaveFiles(files); + + return Json(keyPair_FileDir["building.html"]); + } } } \ No newline at end of file diff --git a/ZipProject/Models/ZipModel.cs b/ZipProject/Models/ZipModel.cs index ada818b..a4faecc 100644 --- a/ZipProject/Models/ZipModel.cs +++ b/ZipProject/Models/ZipModel.cs @@ -1,16 +1,35 @@ -using Ionic.Zip; +using System.IO; +using Ionic.Zip; +using Newtonsoft.Json.Linq; +using System.Collections.Generic; +using System; +using Microsoft.AspNetCore.Http; namespace ZipProject { public class ZipModel { - private readonly string[] _FOTMAT = { "zip", "7z", "rar" }; public ZipModel () { } - public void MakeZip (string name, string format = "zip") { + public string SaveFiles(List files){ + var path= Environment.CurrentDirectory + "/wwwroot/zip/"; + Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; + path += unixTimestamp+"/"; + + foreach(var file in files){ + if (file.Length > 0){ + var filepath= path+ file.FileName; + using(var fileStream= new FileStream(filepath, FileMode.Create)){ + file.CopyTo(fileStream); + } + } + } + + return unixTimestamp+""; + } + + public void MakeZip (JObject keypair, List dirList, List files) { using (ZipFile zip = new ZipFile ()) { - zip.AddDirectory("_zip/test"); - zip.Save("_zip/" + name + ".zip"); } } } diff --git a/ZipProject/Views/WebZip/partial_zip.cshtml b/ZipProject/Views/WebZip/partial_zip.cshtml index 69a4cc7..c017ad3 100644 --- a/ZipProject/Views/WebZip/partial_zip.cshtml +++ b/ZipProject/Views/WebZip/partial_zip.cshtml @@ -48,11 +48,18 @@ -