Unable to upload plugin/theme zip file that created by Windows compression feature

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 года назад
1. Nop Version: 4.20
2. Other software: Windows 10, 7-Zip
3. Expected behavior: Plugin/theme zip file is uploaded into Nop and processed.
4. Actual behavior: Nop throws error "The archive should contain only one root plugin or theme directory. For example, Payments.PayPalDirect or DefaultClean. To upload multiple items, the archive should have the 'uploadedItems.json' file in the root" and the zip file cannot be uploaded.
5. Steps to reproduce:
- Copy the default template folder
- Zip the folder as it is by using the "Send to - Compressed (zipped) folder" within Windows.
- Upload the zip file and Nop will throw the error despite the theme folder structure is correct.
6. Details: After doing some research, I have found some discrepancies in the zip file structure that created by Windows and by other zip program and because of the logic that check for the root folder in the zip file within Nop, it will throws the error even though the folder layout is correct. If you compare the two zip files, one is created by the built-in Windows feature and one by other software (for example, I used 7-Zip and Winrar), the Window zip file is missing the name of the root folder in the first few bytes. Hence, during the uploading process, Nop will use this below code in UploadService.cs to check for root folder name and will throw the error because it is missing:

protected virtual IDescriptor UploadSingleItem(string archivePath)
{
    // Other code
    var rootDirectories = archive.Entries.Where(entry => entry.FullName.Count(ch => ch == '/') == 1 && entry.FullName.EndsWith("/")).ToList(); // Line 88
    // Other code
}
4 года назад
I have the same problem, I cannot upload a zip created with the powershell cmdlet "Compress-Archive" because nopcommerce says "The archive should contain only one root plugin or theme directory. For example, Payments.PayPalDirect or DefaultClean. To upload multiple items, the archive should have the 'uploadedItems.json' file in the root", but the zip structure is correct.
4 года назад
Hi,

We faced same problem then we wrote our own tool. Here is code to do that.

Make a class MyEncoder as below:


class MyEncoder : UTF8Encoding
    {
        public MyEncoder() : base(true)
        {

        }
        public override byte[] GetBytes(string s)
        {
            s = s.Replace("\\", "/");
            return base.GetBytes(s);
        }
    }


Then use this class with System.IO.Compression.ZipFile.CreateFromDirectory method like below:


ZipFile.CreateFromDirectory(selectedFolder, zipPath, CompressionLevel.Fastest, false, new MyEncoder());


In above function, selectedFolder is path of folder to add to archive and zipPath is path to new .zip file.

Hope this will help. Happy coding :)

Best regard's,
Atul Rungta
4 года назад
Hope the helps someone.

I had the same problem. I found that when using the windows zipped folder ie. right-hand click > send to > compressed folder it displayed the same error message. But if you use another program to zip the folder so in my instance I used WinRar it worked fine.  

Steve
3 года назад
[email protected] wrote:
Hope the helps someone.

I had the same problem. I found that when using the windows zipped folder ie. right-hand click > send to > compressed folder it displayed the same error message. But if you use another program to zip the folder so in my instance I used WinRar it worked fine.  

Steve


Thank you Steve, this solution worked for me.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.