Image Upload in 4.2

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
I'm new to nopCommerce and struggling somewhat to find a way to rapidly add product images.
At first I thought I could simply drop them into the wwroot/images folder, add records to Picture adding the file name and path in VirtualPath, then the corresponding map in Product_Picture_Mapping, but that failed.
I then manually added some images to see what it did and realised the image name corresponds to the ID in Picture, so, rather than rename all images I figured I'd use the existing tools to download the existing products, add the image file path and import again. However, that also failed stating "Image cannot be loaded. Available decoders:- PNG : PngDecoder- BMP : BmpDecoder- GIF : GifDecoder- JPEG : JpegDecoder", despite all being jpg's.
This seemed odd but just to make sure, I optimised every image saving as _min.jpg to a new folder. I then modified the filepath on the Excel upload file and tried again but got the same error.
Can anyone suggest what might be wrong?
On a separate note I can see that image management appears to have been an issue in the past and that 3rd party add ons have been created to assist. Can anyone recommend one that is genuinely beneficial?
4 years ago
Others have this problem
https://www.nopcommerce.com/boards/search?searchterms=Image+cannot+be+loaded
Sometimes I had problems. I had to re-edit the file using a working file as a template.
One suggestion is to upload an image to a product the normal way via Admin.
Then see the file that is in then created in the directory.
Then for a test try and upload only that file that which was created.
At the very least this confirms you import process is correct.
4 years ago
Thanks Yidna, I know my method to populate the data directly and upload the files is correct because if I rename an image from something like image_abc123.jpg, to the Picture ID e.g. 0000123_0.jpg it works fine. I'm now looking at writing a script to loop through the picture data and rename each image because I think that will be the fastest way.
4 years ago
[email protected] wrote:
I'm now looking at writing a script to loop through the picture data and rename each image because I think that will be the fastest way.


I did exactly that in Python to get my images from my old store into nop.  Happy to help if you get stuck.
4 years ago
Thanks I might take you up on that. I successfully renamed all the images to correspond with the types of values it expects and have tested this via the product picture mapping to verify I get a result. I then wanted to input all my products and so tried inputting via the Excel Import but this generated an error "Sequence contains no matching element" which isn't too helpful. Any ideas?
4 years ago
Here is the log data


Log level



Error



Short message
Sequence contains no matching element

Full message
System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at Nop.Services.ExportImport.ImportManager.ImportProductsFromXlsx(Stream stream) in C:\andrei\nopcommerce\sources\src\Libraries\Nop.Services\ExportImport\ImportManager.cs:line 1672
   at Nop.Web.Areas.Admin.Controllers.ProductController.ImportExcel(IFormFile importexcelfile) in C:\andrei\nopcommerce\sources\src\Presentation\Nop.Web\Areas\Admin\Controllers\ProductController.cs:line 2280

IP address
127.0.0.1
4 years ago
I've never used the excel import but the conventional advice is to export 1 product to use as a template so you can see what format it expects.  

Not sure whether that's the case, but line 1672 is looking to delete categories so you may need to step through the code to see how things look at this point:


//delete product categories
var deletedProductCategories = categories.Where(categoryId => !importedCategories.Contains(categoryId))
    .Select(categoryId => product.ProductCategories.First(pc => pc.CategoryId == categoryId));
foreach (var deletedProductCategory in deletedProductCategories)
{
    _categoryService.DeleteProductCategory(deletedProductCategory);
}
4 years ago
Error: Sequence contains no matching element

It means you are trying to find an object from a collection (using LINQ .First() method) which not exixsts in that collection. You can resolve this by replacing .First() with .FirstOrDefault(). Click here to know more about these methods.
4 years ago
Thanks for your input mhsjaber but for the avoidance of doubt this error occurred as I tried to input data using the Excel form generated via Product Export and then updating it with new products and going through the Import routine. Therefore, if you are correct this must be an error many have come across before.
4 years ago
[email protected] wrote:
if you are correct this must be an error many have come across before.


Definitely, not sure this has been on nopCommerce forum or not, but already asked so many times on stack overflow.

https://stackoverflow.com/questions/3994336/sequence-contains-no-matching-element

https://stackoverflow.com/questions/47838155/why-am-i-getting-a-sequence-contains-no-matching-element-error-when-using-any

https://stackoverflow.com/questions/22982749/sequence-contains-no-matching-element-entityframework
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.