pictures stored in databse vs filesystem

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 Jahre weitere
hi, i have just downloaded v1.4 and was curious about how the pictures are stored - i have been following topic

https://www.nopcommerce.com/Boards/Topic.aspx?TopicID=906&p=3


which is about storing pictures outside the database and thumbnail quality. I note that v1.4 has improved picture generation but i was looking at v1.4   picturemanager.cs   and (though i'm not a programmer)  it looks like the pictures are still saved to the database.

I particularly want the files saved to the file system rather than to the database and was following the advice in the above post for a new (then) version of  picturemanager.cs  which offered improved thumbnail image generation and stored images in the filesystem. Perfect for me !


However, I see that picturemanager.cs  is now stored in a different location
(Nop.BusinessLogic/media/       rather than Nop.Common/media/    )

so I would like to know :
1) does nopcommerce still save images in the database

2) if so then does the new picturemanager.cs  create as good as/better quality images (and thumbnails) than picturemanager.cs  fix from the above post

3) assuming that images are still saved in the database, is the fix from the above post going to work with v1.4

4) if I compile the project with the picturemanager.cs changes, can i copy just a couple of the files ie
Nop.BusinessLogic.dll
Nop.BusinessLogic.pdb
Nop.BusinessLogic.xml
into the bin folder of existing v1.4 websites rather than recompile each one ?

thanks, hayden
14 Jahre weitere
The picture manager yes still stores images in the database.   For a future upgrade would love to see a nop_setting with the option of store images in the file system.

Hayden I 'm going to need storing images in the filesystem on the project I am working on.  So give me a day and I'll get this sorted.

Thanks,
Matthew
14 Jahre weitere
hi mathew
did you see the post by miles in the above link,

he had provided the a whole new picturemanager.cs file as a download,

https://www.nopcommerce.com/Boards/Topic.aspx?TopicID=906&p=3

i was testing it a couple of days ago and it works fine - better thumbnails, stores pictures in filesystem, (and makes small marker in database)

it was for v1.3 i am wondering if it will be easy to include in v1.4 - i expect it will

- hayden
14 Jahre weitere
scratch that

tried compiling the project with picturemanager.cs fix but it threw 80+ errors so i guess its safe to say that it does'nt work for v1.4 which is a shame - as i said, it worked perfectly on v1.3

i'm not a programmer so i can't offer any help on this but I would certainly like to be able to use filesystem

-hayden
14 Jahre weitere
Okay I will take a look.
14 Jahre weitere
Okay I'm not sure if this solution is good for you. But here goes.  I wanted to implement so I could use the same system on another site with the option of storing pictures locallly or in the db (you still need to decide at the beginning not after you've added products).  

This might be a little over the top but it seems to work.

STEPS

-Add a new setting in the Administration Panel called "Pictures.InsertToDatabase" and give it a value of false or true.

-In DBPicture Provider (\Libraries\Nop.DataAccess\Media\DBPictureProvider.cs) add a new abstract like so:
      
          
public abstract DBPicture InsertPicture(string Extension, bool IsNew);



-In SQLPictureProvider \Libraries\Nop.DataAccess.SqlServer\Media\SQLPictureProvider.cs) you now need to implement the above method like so:

        public override DBPicture InsertPicture(string Extension, bool IsNew)
        {
            DBPicture picture = null;
            Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString);
            DbCommand dbCommand = db.GetStoredProcCommand("Nop_PictureInsertNoImage");
            db.AddOutParameter(dbCommand, "PictureID", DbType.Int32, 0);
            db.AddInParameter(dbCommand, "Extension", DbType.String, Extension);
            db.AddInParameter(dbCommand, "IsNew", DbType.Boolean, IsNew);
            if (db.ExecuteNonQuery(dbCommand) > 0)
            {
                int PictureID = Convert.ToInt32(db.GetParameterValue(dbCommand, "@PictureID"));
                picture = GetPictureByID(PictureID);
            }
            return picture;
        }


In the database you then need to alter the PictureBinary column in Nop_Picture to allow nulls.

You need to create a new stored procedure in the database like so:

CREATE PROCEDURE [dbo].[Nop_PictureInsertNoImage]
(
  @PictureID int = NULL output,
  @Extension nvarchar(20),
  @IsNew  bit
)
AS
BEGIN
  INSERT
  INTO [Nop_Picture]
  (
    Extension,
    IsNew
  )
  VALUES
  (
    @Extension,
    @IsNew
  )

  set @PictureID=@@identity
END


The replace pictureManager(\Libraries\Nop.BusinessLogic\Media\PictureManager.cs)  with

http://www.agentx.info/PictureManager.txt
14 Jahre weitere
found the edit post button :)
14 Jahre weitere
nice work matthew, i will try and implement this later today -
14 Jahre weitere
i'm using vs2010 (beta2) which i downloaded and used for the first time a few days ago - i did'nt use vs2008 before so as a disclamer, i maybe didn't do everything properly !! anyway, when i first load the project into vs2010 is converts everything to the current version (i still select .net 3.5 though) i make the changes in the 3 .cs files and select publish to file system  - it shows a lot of warnings but no errors and publishes the store.

I ran the create stored procedure in my sample database, check to see if it worked - it's there

i run the store and it operates

i go to admin manage products -->add new product though i cannot see if i can decide where to put images. create product, select a picture to upload but get following error:

Cannot insert the value NULL into column 'PictureBinary', table 'test1.dbo.Nop_Picture'; column does not allow nulls. INSERT fails. The statement has been terminated.

i checked the database again and the stored procedure is definately there. as usual, its late and i would probably be best waiting untill the morning to see where i went wrong



I hope the team are watching this - they seem to have thier minds set on storing images in the database - why not let the user decide?

ok, until later ..
14 Jahre weitere
You didn't read my instructions throughly enough :)

You need to alter the Nop_Picture table and change the PictureBinary table so it allows nulls.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.