We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Loading zip file and expanding on server side

With the File Manager component, I am able to upload single file. I would like to upload zip files and then uncompress the zip file on the server side so that whole folder can be uploaded to the server. How can I accomplish that in the File Manager component controller?

Amjad.


4 Replies

IL Indhumathy Loganathan Syncfusion Team February 27, 2023 02:24 PM UTC

Hi Amjad,


Greetings from Syncfusion support.


In the File Manager component, you are able to upload a zip folder. But we were not clear about your exact requirement for extracting them at the server end. Whether you are using a Physical File Provider and want to extract the zip folder in your Windows Explorer Or do you want to do this folder extraction programmatically at the server end? Confirm your File Service provider to assist you promptly.


Also, we would like to let you know that we have already considered a directory (folder) upload feature in the Blazor File Manager component. Usually, Syncfusion will plan and implement the features based on feature rank, customer requested count, and volume wish-list. This will be included in any of our upcoming releases.


The status of this feature can be tracked through our feedback portal below.

https://www.syncfusion.com/feedback/38684/need-to-provide-upload-folder-support-in-the-blazor-filemanager-component


You can get back to us if you need any further assistance.


Regards,

Indhumathy L



AK Amjad Khan February 28, 2023 01:58 AM UTC

Yes we would like to extract the zip file at the server end programmatically.



AK Amjad Khan March 6, 2023 01:31 AM UTC

Can someone please look into this and recommend a solution?



IL Indhumathy Loganathan Syncfusion Team March 7, 2023 01:19 PM UTC

Amjad, We have achieved your requirement by customizing our Physical File Service provider's "Upload" operation. In the sample, we have used the ZipFile.ExtractToDirectory method to extract the zip file to the specified directory. Check out the below code snippet.


[PhysicalFileProvider.cs]

public virtual FileManagerResponse Upload(string path, IList uploadFiles, string action, params FileManagerDirectoryContent[] data)

{

     FileManagerResponse uploadResponse = new FileManagerResponse();

     ...

     foreach (IFormFile file in uploadFiles)

     {

       if (uploadFiles != null)

      {

         var name = System.IO.Path.GetFileName(file.FileName);

         var fullName = Path.Combine((this.contentRootPath + path), name);

         ...

         string fileName = folders[folders.Length - 1];

         var fullName = Path.Combine((this.contentRootPath + path), fileName);

         fullName = fullName.Replace("../", "");

         ...

         if ((file.FileName).Split('.')[1] == "zip")

        {

          string zipPath = fullName;

          string extractPath = this.contentRootPath + path;

          //Extract the zip folder.

         ZipFile.ExtractToDirectory(zipPath, extractPath);

         //Here, we deleted the zip file which is uploaded.

         File.Delete(zipPath);

       }

    }

 }

 ...

 return uploadResponse;

 }

...

}


The zipPath variable is the path of the zip file that you want to extract and extractPath is the path of the directory where you want to extract the contents of the zip file.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorFileManager-230700855


Check out the attached sample and get back to us if you need any further assistance.


Loader.
Up arrow icon