Restricting image sizes and resizing on upload

Posted by Community Admin on 03-Aug-2018 13:51

Restricting image sizes and resizing on upload

All Replies

Posted by Community Admin on 08-Feb-2013 00:00

Hi

What's the current best way to manage users who insist on uploading massive images?

I know that each library can have it's own restrictions on file size and pixel dimensions, but inevitably a user will create new library and not know to, not care about, or intentional avoid, setting these correctly, and then they'll be free to upload whatever they want.

Is there any global settings that can be applied that would restrict/resize uploads to a maximum pixel size?

thanks

Posted by Community Admin on 13-Feb-2013 00:00

Hello Nick,

Thank you for contacting us.

Currently, there is no way to set a global maximum for images being uploaded. To achieve that you would need to create a custom DataProvider, which serves as an intermediary between programmatic CRUD operations and the database.

Basically, you need to create a new provider and inherit from the default LibrariesDataProvider. Then you can override the UploadImage method to include your custom logic. Make sure to set the ResizeOnUpload property to false such as:

using System;
using System.Linq;
using Telerik.Sitefinity.Modules.Libraries.Data;
  
namespace SitefinityWebApp
    public class LDPC : OpenAccessLibrariesProvider
    
        protected override void UploadImage(Telerik.Sitefinity.Libraries.Model.Image image, System.IO.Stream source, string mimeType)
        
            image.Album.ResizeOnUpload = false;
            //custom resize logic ...
            base.UploadImage(image, source, mimeType);
        
    

For more information on how to substitute the default libraries provider with your custom one once you've implemented and built the class you can check this blog post, I hope you find it useful.

All the best,
Randy Hodge
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

This thread is closed