Best way to insert images programmatically in nop 2.7/2.8?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hi,
Before I spend ages digging through code, does anyone know if it's easy to insert product images programmatically in Nop 2.70 or 2.80?  Is it just a matter of creating the link in the database in the Picture and Product_Picture_Mapping tables, or do I need to resize the images and pre-generate the thumbnail images?

I can't seem to find out if the thumbnails are generated when required or if I need to call a function to pregenerate them at the time I insert the image?

Thanks
Nick
11 years ago
You can pass a Variable through openrowset command using Dynamic SQL. On excution of the Stored procedure you will need to set the file path of the directory using dbo.xp_cmdshell. This will insert all indivdual images. I'm using 2.4 btw.
11 years ago
wertyuio1 wrote:
You can pass a Variable through openrowset command using Dynamic SQL. On excution of the Stored procedure you will need to set the file path of the directory using dbo.xp_cmdshell. This will insert all indivdual images. I'm using 2.4 btw.


Why would I need to use xp_cmdshell though?  To clarify, I'm not trying to store the actual image binaries in the DB - just in the filesystem. I only need to add the references to filenames in the DB to ensure they are displayed on the front end.
11 years ago
nmg196 wrote:

I only need to add the references to filenames in the DB to ensure they are displayed on the front end.


How would you propose to this I have been testing storing in both db and filestream for filestream I was advised to set a Virtual Directory in IIS and both option's seem to display image's.

You may not need to use cmdshell we did for certain reasons.

EDIT: Im storing out of the Image directory based in the Site to add.
11 years ago
nmg196 wrote:
Hi,
Before I spend ages digging through code, does anyone know if it's easy to insert product images programmatically in Nop 2.70 or 2.80?  Is it just a matter of creating the link in the database in the Picture and Product_Picture_Mapping tables, or do I need to resize the images and pre-generate the thumbnail images?

I can't seem to find out if the thumbnails are generated when required or if I need to call a function to pregenerate them at the time I insert the image?

Thanks
Nick


I think all you need to do is insert the info into the Picture table and use that ID in the filename as you copy the image to the correct directory.

The thumbnails will get generated by the site when the Picture service requests it at a size that doesn't exist so no worries there.
11 years ago
AndyMcKenna wrote:
I think all you need to do is insert the info into the Picture table and use that ID in the filename as you copy the image to the correct directory.

The thumbnails will get generated by the site when the Picture service requests it at a size that doesn't exist so no worries there.


That's what I'd hoped... I will confirm here once I've tested it.

Does anyone know what the IsNew flag does on the Picture table?
11 years ago
If you call GetPictureUrl, it checks for IsNew and if it's true:


DeletePictureThumbs(picture);

//we do not validate picture binary here to ensure that no exception ("Parameter is not valid") will be thrown
picture = UpdatePicture(picture.Id,
                    pictureBinary,
                    picture.MimeType,
                    picture.SeoFilename,
                    false,
                    false);


I'm not really sure what's happening here.  If the picture is new, why would there be any thumbs to delete?
11 years ago
Ahh, perhaps there is (or was) a function to replace an existing image (but keeping it's ID)?
In which case the thumbnails will be of the old image and will need to be regenerated even if they already exist?
11 years ago
AndyMcKenna wrote:
If you call GetPictureUrl, it checks for IsNew and if it's true:

I'm not really sure what's happening here.  If the picture is new, why would there be any thumbs to delete?


Good Question as Im currently testing updating or deleting an image that is allready stored in the filesystem

Could be to overide the existing image is there is a label change etc.
11 years ago
OK - let me know what you find out as I'm likely to need to do exactly the same thing in the next day or so. If you have any code samples for programmatically inserting images, that would be useful too :)  I'm trying to modify the API to allow an external service to insert and update products and categories etc.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.