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
return Redirect ("/");
}
+ public JsonResult FileUpload(List<string> dirList, List<IFormFile> 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
-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<IFormFile> 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<string> dirList, List<IFormFile> files) {
using (ZipFile zip = new ZipFile ()) {
- zip.AddDirectory("_zip/test");
- zip.Save("_zip/" + name + ".zip");
}
}
}
<label class="btn btn-danger webzip-btn-choosefile" for="btn_newDirectory">\r
@LanguagePack.GetText(lang, "newFolder")\r
</label>\r
- <label class="btn btn-danger webzip-btn-choosefile">\r
+ <label class="btn btn-danger webzip-btn-choosefile" onclick="alert(_Language['comingsoon'])">\r
@LanguagePack.GetText(lang, "howtouse")\r
</label>\r
</td>\r
</tr>\r
+ <tr>\r
+ <td colspan="2">\r
+ <label class="btn btn-danger webzip-btn-choosefile" onclick="RequestCompress();">\r
+ @LanguagePack.GetText(lang, "compress")\r
+ </label>\r
+ </td>\r
+ </tr>\r
</table>\r
</div>\r
<div class="col-sm-7 webzip-section-sidezip webzip-section-explore" id="zipExplore"\r
"duplicateName": "It can not have the same name as a file already added:",
"addDirectory": "Add Directory",
"howtouse": "How to use",
- "comingsoon": "Coming soon"
+ "comingsoon": "Coming soon",
+ "compress": "Compress!"
}
"duplicateName": "이미 추가되어있는 파일과 이름이 같을수 없습니다 : ",
"addDirectory": "폴더추가",
"howtouse": "사용법",
- "comingsoon": "준비중입니다."
+ "comingsoon": "준비중입니다.",
+ "compress": "압축시작!"
}
selected.append(directory);
//directories 객체에 폴더 오브젝트 추가
directories.put(directories.keys().length + "", "new");
-
+
//bullet 리셋, sort리셋
SetBulletIcon();
SetSortable();
);
});
- console.log(directory_key+","+directory_infiles);
MoveFile(directory_key, directory_infiles);
}
})
return false;
}
+//압축 시작(백단에 파일들과 파일정보 map 전송)
+function RequestCompress() {
+ //디렉토리 리스트
+ var dirList = new Array();
+ for (var i = 0; i < directories.keys().length; i++) {
+ dirList.push(directories.get(i));
+ }
+
+ //파일이 몇번째 디렉토리에 들어있는지에 대한 정보 json값
+ var fileKeyPair = "{";
+ for (var i = 0; i < files.keys().length; i++) {
+ fileKeyPair +=
+ '"' +
+ files.get(i).get("file").name +
+ '" : "' +
+ files.get(i).get("directory") +
+ '"';
+ if (files.keys().length -1 != i){
+ fileKeyPair+=", ";
+ }
+ }
+ fileKeyPair += "}";
+
+ var formdata = new FormData();
+ for (var i = 0; i < files.keys().length; i++) {
+ formdata.append("files", files.get(i).get("file"));
+ }
+ formdata.append("fileKeyPair", fileKeyPair);
+ formdata.append("dirList", dirList);
+
+ $.ajax({
+ type: "post",
+ url: "/webzip/fileupload",
+ data: formdata,
+ processData: false,
+ contentType: false
+ }).done(function(data){
+ alert(data);
+ })
+
+}
+
//초기세팅(bullet, sort, 기본 zip label 세팅)
SetBulletIcon();
SetSortable();