CommunityServer 2.1 Tips: Gallery photo options, save to DB or save to file...
crosspost from http://rextang.net/blogs/work/
Just had a trace to the source code since I found some of my gallery photos were missing and not able to get them back while upgrading my blog site to CS 2.1 in my VM.
Later found that in .Text era, images were saving to DB only; later in CS 1.x era, images were changed to save to files to minimize DB space usage. now in CS 2.1 , it can now be set to either places, or both.
in CS 1.x , the default image saving location is at ~/photos/storage , while it's the same as in CS 2.1 , if you find your images missing to display on browser, remember to copy all the files in ~/photos/storage of CS 1.x web spaces.
in CS 2.1, now there are options to let you set where to save, DB or file, or both. refer to default CommunityServer.config file , like the following:
<Gallery
allowEncodedUnicodeCharsInMetadata="true"
>
<AttachmentSettings
enableFileSystemStorage="true" fileSystemStorageLocation="~/photos/storage"
enableDataStoreStorage="true" enableDirectLinks="false"
extensions = "gif,jpg,jpeg,png,bmp,GIF,JPEG,JPG,PNG,BMP,Gif,Jpg,Jpeg,Png,Bmp" />
<CacheSettings
enableFileSystemStorage="true" fileSystemStorageLocation="~/photos/cache"
enableDataStoreStorage="false" enableDirectLinks="false"
/>
</Gallery>
AttachmentSettings is the place to toggle where to save images to. if set both enableFileSystemStorage and enableDataStoreStorage to true, not only image files will be create and save in ~/photos/storage folder, but also will be saved to database record binary field (cs_PostAttachment table). Refer to GalleryPosts.cs file of CommunityServerGalleries20 project (started from line 387):
//TODO: work on new save attachement patterns
private static void CreatePictureData(GalleryPost galleryPost, PostAttachment pictureData)
{
// Submit it to the database
if (GalleryConfiguration.Instance().AttachmentSettings.EnableDataStoreStorage && pictureData.HasDateCreated)
CommonDataProvider.Instance().AddPostAttachment(galleryPost, pictureData);
else
{
PostAttachment noPictureData = new PostAttachment(pictureData);
noPictureData.Content = null;
CommonDataProvider.Instance().AddPostAttachment(galleryPost, noPictureData);
}
// If file system storage is enabled, we need to save it.
if (GalleryConfiguration.Instance().AttachmentSettings.EnableFileSystemStorage)
CreateDataFile(galleryPost, pictureData);
}
basically this checks both flags to see if they are true, and then save to each places (DB and file). but if DataStoreStorage flag is false, then while saving the data record, will set Content binary field to null.
By default setting in CS 2.1 , it seems set both DB and file flags to true. To preserve the same usage as in CS 1.x , it's needed to change the enableDataStoreStorage to false.
CacheSettings also using the same setting pattern as AttachmentSettings, but actually DataStore support for Cache is currently not supported in this version, as stated in the comment of CommunityServer.config file.
Technorati Tags: communityserver , asp.net , programming