-using System.Threading;
+using System.Net.Http;
+using System.IO;
+using System.ComponentModel;
+using System.Threading;
using System.Diagnostics;
using System;
using System.Collections.Generic;
//파일업로드 사이즈 3GB (3(GB) * 1024(MB) * 1024(KB) * 1024(byte))
[RequestSizeLimit(3221225472)]
public ActionResult FileUpload(string dirList, List<IFormFile> files, string fileKeyPair, string format){
+ string userId= Request.HttpContext.Connection.Id;
JObject keyPair_FileDir= JObject.Parse(fileKeyPair);
+ Dictionary<string, object> data= new Dictionary<string, object>();
ZipModel zipModel= new ZipModel();
+ ZipLists.AddZipList(userId, zipModel);
+
string[] listDir= dirList.Split(',');
- var zip= zipModel.MakeZip(keyPair_FileDir, listDir, files);
string filename= listDir[0]+"."+format;
+
+ zipModel.MakeZip(keyPair_FileDir, listDir, files, userId);
+
+ // return File(zip.ToArray(), "application/zip");
+ return Json(Thread.CurrentThread.ManagedThreadId);
+ }
- return File(zip.ToArray(), "application/zip");
+ public ActionResult FileUploadProgress(){
+ string userId= Request.HttpContext.Connection.Id;
+ return Json(ZipLists.GetZipList(userId).getNow());
}
public ActionResult Error(){
--- /dev/null
+using System;
+using System.Collections.Generic;
+
+namespace ZipProject.Models {
+ public static class ZipLists {
+ private static Dictionary<string, ZipModel> ZipModel= new Dictionary<string, ZipModel>();
+
+ public static ZipModel GetZipList(string userId){
+ return ZipModel["userId"];
+ }
+
+ public static void AddZipList(string userId, ZipModel zip){
+ ZipModel.Add(userId, zip);
+ }
+
+ }
+}
\ No newline at end of file
using System;
using System.Collections;
using System.Collections.Generic;
+using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
namespace ZipProject {
public class ZipModel {
private readonly string[] _FOTMAT = { "zip", "7z", "rar" };
+ private int now;
public ZipModel () { }
- public MemoryStream MakeZip (JObject keypair, string[] dirList, List<IFormFile> files) {
- MemoryStream memoryStream = new MemoryStream ();
+ public void MakeZip (JObject keypair, string[] dirList, List<IFormFile> files, string zipname) {
+ byte[] b = null;
+ string filename = null;
+ string dir = null;
+ string path = Environment.CurrentDirectory + "/wwwroot/zipfiles/" + zipname + ".zip";
using (var zip = new ZipFile (Encoding.UTF8)) {
- byte[] b = null;
- string filename = null;
- string dir = null;
-
foreach (IFormFile file in files) {
+ zip.AddProgress += AddProgressHandler;
+ zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default;
+ zip.SaveProgress += SaveProgress;
+
//keypair 디렉토리 키값이 0(압축파일 최상단에 놓여야할 파일)일경우 "" 아닐경우 디렉토리명/파일 식으로 세팅
dir = ((string) keypair[file.FileName] == "0") ? "" : dirList[Int32.Parse ((string) keypair[file.FileName])] + "/";
//시스템의 기본 인코딩 타입으로 읽어서
//파일을 zip엔트리에 추가
zip.AddEntry (dir + filename, file.OpenReadStream ());
}
+ zip.Save (path);
+ }
+ }
+
+ int _numEntriesAdded = 0;
+ void AddProgressHandler (object sender, AddProgressEventArgs e) {
+ switch (e.EventType) {
+ case ZipProgressEventType.Adding_Started:
+ _numEntriesAdded = 0;
+ break;
+ case ZipProgressEventType.Adding_AfterAddEntry:
+ _numEntriesAdded++;
+ break;
+ case ZipProgressEventType.Adding_Completed:
+ Console.WriteLine("end");
+ now= -1;
+ break;
+ }
+ }
- //메모리스트림에 저장
- zip.Save (memoryStream);
+ public void SaveProgress (object sender, SaveProgressEventArgs e) {
+ if (e.EventType == ZipProgressEventType.Saving_Started) {
+ Console.WriteLine ("Begin Saving: " + e.ArchiveName);
+ } else if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry) {
+ Console.WriteLine ("Processing : " + e.CurrentEntry.FileName);
+ Console.WriteLine ("Files Processed: (" + (e.EntriesSaved + 1) + "/" + e.EntriesTotal + ")");
+ now= e.EntriesSaved +1;
+ } else if (e.EventType == ZipProgressEventType.Saving_EntryBytesRead) {
+ //개별파일의 진행률.. 안씀
}
- //zip파일 return
- return memoryStream;
+ }
+
+ public int getNow(){
+ return now;
}
}
+
}
\ No newline at end of file
using System;\r
using System.Collections.Generic;\r
using System.Linq;\r
+using System.Net.WebSockets;\r
+using System.Threading;\r
using System.Threading.Tasks;\r
using Microsoft.AspNetCore.Builder;\r
using Microsoft.AspNetCore.Hosting;\r
name: "default",\r
template: "{controller=WebZip}/{action=Index}/{id?}");\r
});\r
+\r
}\r
}\r
}
\ No newline at end of file
data: formdata,
processData: false,
contentType: false,
- xhrFields: {
- responseType: "blob"
- },
+ // xhrFields: {
+ // responseType: "blob"
+ // },
success: function(data) {
- var a = document.createElement("a");
- var url = window.URL.createObjectURL(data);
- a.href = url;
- a.download = directories.get(0) + "." + format;
- a.click();
- window.URL.revokeObjectURL(url);
+ // var a = document.createElement("a");
+ // var url = window.URL.createObjectURL(data);
+ // a.href = url;
+ // a.download = directories.get(0) + "." + format;
+ // a.click();
+ // window.URL.revokeObjectURL(url);
+ var now;
+ while(now != -1){
+ $.ajax({
+ type: "post",
+ url: "/webzip/fileuploadprogress",
+ }).done(function(data){
+ now= data;
+ console.log(data);
+ })
+ }
$(".modal").css("display", "none");
+ var socket = new WebSocket();
}
});
}
}
if (isErrFileName($elem.val())) {
alert(_Language["err_violationFileName"]);
- $elem.val("dir "+ (++sameDir));
- }
- else if (isTooLongFileName($elem.val())) {
+ $elem.val("dir " + ++sameDir);
+ } else if (isTooLongFileName($elem.val())) {
alert(_Language["err_tooLongFileName"]);
- $elem.val("dir "+ (++sameDir));
- }
- else {
+ $elem.val("dir " + ++sameDir);
+ } else {
directories.put($elem.prev().attr("key"), $elem.val());
}
$elem.prev().text($elem.val());
SetBulletIcon();
SetSortable();
directories.put(0, "example");
+
+// var protocol = location.protocol === "https:" ? "wss:" : "ws:";
+// var wsUri = protocol + "//" + window.location.host + "/ws";
+// var socket = new WebSocket(wsUri);
+// socket.onopen = e => {
+// console.log("socket opened", e);
+// };
+// socket.onclose = function(e) {
+// console.log("socket closed", e);
+// };
+// socket.onmessage = function(e) {
+// console.log(e);
+// };
+// socket.onerror = function(e) {
+// console.error(e.data);
+// };