Adding an image field to a custom module in 4.2

Posted by Community Admin on 04-Aug-2018 17:02

Adding an image field to a custom module in 4.2

All Replies

Posted by Community Admin on 16-Jan-2012 00:00

What's the best method for adding images to a custom module?

I've tried specifying the type of the backing field as a string and using the following as the backend editor:

var bSpotImage = new ImageFieldElement(bSpotSection.Fields)
    ID = "bSpotImageField",
    DataFieldName = "BSpotImage",
    Title = "BSpot Image",
    DisplayMode = displayMode,
    CssClass = "sfFormSeparator sfContentField",
    WrapperTag = HtmlTextWriterTag.Li,
    FieldType = typeof(Telerik.Sitefinity.Web.UI.Fields.ImageField)
;

But that code always forces a resize on upload. What am I doing wrong? 

Posted by Community Admin on 17-Jan-2012 00:00

Hello,

 If you are using Sitefinity 4.2.1650 there is a bug that is fixed in the hotfix for 4.1.1650. The bug was reducing the size of the image on upload

var productImageField = new ImageFieldElement(mainSection.Fields)
            
                ID = "avatarField",
                DataFieldName = "ProductImage",
                DisplayMode = displayMode,
                UploadMode = ImageFieldUploadMode.Dialog,
                Title = "ProductImageFieldTitle",
                WrapperTag = HtmlTextWriterTag.Li,
                CssClass = "sfUserAvatar",
//specify your module resources here
                ResourceClassId = typeof(ProductsResources).Name,
                DataFieldType = typeof(ContentLink),
                DefaultSrc = "~/SFRes/images/ProductCatalogSample/Images.NoProductImage.png",// put your default image location example if available, if not remove the line:
//this specifies the resizing during upload
                SizeInPx = 100
            ;
If this is not specified "SizeInPx" it will take a default value. SizeInPx is a configuration property of the ImageFieldElement so it is better to set is explicitly to a required value.
Greetings,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 17-Jan-2012 00:00

I am running 4.2.1650. Can you provide a link to this hotfix? 

Thanks for your help.

Posted by Community Admin on 18-Jan-2012 00:00

Hi,

Excuse me I was mistaken the problem with images being resized was in Sitefinity 4.3.1873 and was fixed in 4.3.1885(the problem was when uploading an image with size 1mb displaying and downloading it returned an image of 200Kb which reduces quality).

In this case I suppose the problem in SizeInPx propery for the ImageFieldElement.
If this doesn`t help can you elaborate a little more about is the resize in image size in (Kb, Mb) or in size (pixels).

All the best,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 18-Jan-2012 00:00

Both? It seems to be primarily a change in dimensions. I've outlined what I think are the important bits below. 

From the Definitions:

var landingImage = new ImageFieldElement(landingSection.Fields)
    ID = "landingImageUrl",
    DataFieldName = "LandingImageUrl",
    Title = "Landing Image Url",
    DisplayMode = displayMode,
    CssClass = "sfFormSeparator sfContentField",
    WrapperTag = HtmlTextWriterTag.Li,
    FieldType = typeof(Telerik.Sitefinity.Web.UI.Fields.ImageField),
    SizeInPx = 448
;
landingSection.Fields.Add(landingImage);

From the Model:
[DataMember]
public string LandingImageUrl get; set;

From the View Model:
public string LandingImageUrl get; set;

Specifying the SizeInPx property seems to have no effect whatsoever. After uploading test.jpg  the database contains the following url localhost/.../test.jpg.tmb and has been reduced in size.



Posted by Community Admin on 18-Jan-2012 00:00

FYI, I've created a support ticket where you can find the source for the entire module.

This thread is closed