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, ... .
1 Answer(s)
-
0
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); } } }