Image files and AllowedTypes

Vote:
 

I have a generic ImageFile content type that uses MediaDescriptor for jpeg, gif, png, svg etc.

Now I have a requirement to restrict the type of file a particular content reference can take to only jpeg. (To stop people from using massive PNGs or BMPs for a certain property).

Is there any reason why I shouldn't just create a contenttype for each file type so that I can use the AllowedTypes attribute accordingly? So I'd have something like this:

  [ContentType(GUID = "someguid")]
  public class ImageFile: ImageData
  {
public virtual string Copyright { get; set; }
  }  

[ContentType(GUID = "anotherguid")]
  [MediaDescriptor(ExtensionString = "jpg,jpeg,jpe")]
  public class JpegFile: ImageFile
  {
  }

  [ContentType(GUID = "anotherguid")]
  [MediaDescriptor(ExtensionString = "png")]
  public class PngFile: ImageFile
  {


  }

  [ContentType(GUID = "anotherguid")]
  [MediaDescriptor(ExtensionString = "ico")]
  public class IcoFile: ImageFile
  {

  }

// then I can do this:
        [AllowedTypes(typeof(JpegFile))]
        public virtual ContentReference Photo{ get; set; }

I guess I'm wondering what effect that would have on existing images that were uploaded as an ImageFile originally.

#151068
Jul 11, 2016 3:26
Vote:
 

Looks good

#151070
Jul 11, 2016 8:00
Vote:
 

Nothing happens with the already uploaded files.

You can also create a custom validator instead of having a lot of content types, see IValidate here http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-CMS/7/Validation/Validation/

#151076
Jul 11, 2016 9:57
Vote:
 

Had a similar problem a few months ago and solved it by using image resizer which both convert to jpg and scales image on the fly (with excellent disc cashing for performance).

Then your editors can upload whatever but you will still have great performance front end...

This solution worked great for me and took an hour or so to implement (and some hours more to change some image urls)

http://world.episerver.com/code/Martin-Pickering/ImageResizingNet-integration-for-CMS75/

Might be an alternative which requires no editor work...

#151085
Jul 11, 2016 14:15
Vote:
 

Great, thanks guys!

#151321
Jul 15, 2016 3:04
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.