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

Posted: June 03, 2019 at 10:23 PM Quote #237095
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
}
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: July 11, 2019 at 4:55 AM Quote #242409
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.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: July 11, 2019 at 5:12 AM Quote #242410
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
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Need any professional assistance? Drop us your requirements on [email protected] or Skype @ live:nopadvance.sales

https://nopadvance.com
nopCommerce Solution Partner
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2019
Learn more