Open Closed

User profile picture set maximum file upload limit #3648


User avatar
0
abpfintranet-1 created

Hi How can we set a file limit size for user profile picture. It seems no limit has set and I could upload a 10 MB file. I want to set like maximum 1MB, or 2Mb, ... .

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi @abpfintranet-1, you can override the SetProfilePictureAsync method of the AccountAppService class and check whether the file size exceeds or not:

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IAccountAppService), typeof(AccountAppService), typeof(MyAccountAppService))]
    public class MyAccountAppService : AccountAppService
    {
        [Authorize]
        public override async Task SetProfilePictureAsync(ProfilePictureInput input)
        {
            //check the file size and do not proceed if it's exceeded
            if(input.ImageContent.ContentLength > MaxFileSize)
            {
                return; //or throw exception
            }
             
            //file size not exceeded so, continue to set profile picture...
            
            await SettingManager.SetForUserAsync(CurrentUser.GetId(), AccountSettingNames.ProfilePictureSource, input.Type.ToString());
    
            var userIdText = CurrentUser.GetId().ToString();
    
            if (input.Type != ProfilePictureType.Image)
            {
                if (await AccountProfilePictureContainer.ExistsAsync(userIdText))
                {
                    await AccountProfilePictureContainer.DeleteAsync(userIdText);
                }
            }
            else
            {
                if (input.ImageContent == null)
                {
                    throw new NoImageProvidedException();
                }
    
                await AccountProfilePictureContainer.SaveAsync(userIdText, input.ImageContent.GetStream(), true);
            }
        }
     }
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.