0

Currently I have this problem, I am developing an MVC application for selling photos, I have a zip file that weighs 50mb that contains a list of photos, I want that when I press a button it will split that file into several zip files that weigh 10mb, try to do it by my account but the only thing I achieved is that it recreated the file with the same weight, that is, 50mb.

I tried to do the following: unzip the zip file and save it in a folder, I declared a variable to establish the maximum that each zip would have, that is, 10mb, and I did a do while loop to create the zip with the files that I saved in the folder as long as the weight of the zip that I am creating did not exceed 10mb and I was accumulating that weight to start doing the validation.

researching I found this link but it is not entirely clear to me

Split zip file using DotNetZip Library


[HttpPost]
        public IActionResult GenerateCompressFiles()
        {
            string dateCapture = DateTime.Now.ToString("ddMMyyyy");
            string timeCapture = DateTime.Now.ToString("hhmmss");
            string directory = Path.Combine(_env.ContentRootPath, "Uploads");
            string outputDirectory = Path.Combine(_env.ContentRootPath, "Uploads/ZipTest");

            if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);

            string curFile = $"{directory}/MatiposExperencias-5345435435454.zip";
            string zipFile = $"{directory}/MatiposExperencias-{dateCapture}{timeCapture}.zip";
            var fileInfo = new FileInfo(zipFile);

            using (ZipFile zip = ZipFile.Read(curFile))
            {
                zip.ExtractAll(outputDirectory, ExtractExistingFileAction.OverwriteSilently);
            }

            do
            {
                //Create A New Zip Archive
                using (ZipFile zipDest = new ZipFile())
                {
                    zipDest.AddFiles((System.IO.Directory.EnumerateFiles(outputDirectory)), false, ""); //This will add the files to the root
                    zipDest.Save(zipFile);
                }

                _currentArchiveSize += fileInfo.Length;

            } while (_currentArchiveSize >= _maxArchiveSize
                || _currentArchiveSize + fileInfo.Length >= _maxArchiveSize);

            return RedirectToAction("Index","Home");
        }
pipex98
  • 1
  • 1
  • What you want is the "spanned" zip file described in the other question. – Robert Harvey Dec 03 '22 at 22:17
  • Code example here: https://stackoverflow.com/q/6671811 – Robert Harvey Dec 03 '22 at 22:18
  • @robert harvey that is not what I want, I want is to divide a 50mb zip into sections of 10 when I mean sections is to create other zips with that size. – pipex98 Dec 03 '22 at 22:21
  • OK, but why would you want to do that any other way besides a spanned zip? Presumably the idea is to eventually merge the files back together on the other side so that you have a single zip that works correctly, right? – Robert Harvey Dec 03 '22 at 22:23
  • @Robert Harvey because the idea is that these zips can be downloaded separately in the application from a button for each zip, I don't know if I understand myself, the idea is not to make the download so heavy for the user. – pipex98 Dec 03 '22 at 22:27
  • Your users are still going to need a way to reassemble the zip fragments. You need it to be a spanned zip to do that. What am I missing here? – Robert Harvey Dec 03 '22 at 22:38
  • @Robert Harvey is that I don't need to reassemble the zip fragments, I want to replicate the following https://www.youtube.com/watch?v=5dozv4_usi0&t=46s&ab_channel=krusnik – pipex98 Dec 03 '22 at 22:43
  • Don't add all of the files to the first zip? Save some of them for the second, and third? Rinse and repeat? – Robert Harvey Dec 03 '22 at 22:44
  • @Robert Harvey Exactly, the first I already did, I need the second – pipex98 Dec 03 '22 at 22:48

0 Answers0