public ActionResult DownloadTempFile(FileDto file) { var fileBytes = _dataTempFileCacheManager.GetFile(file.FileToken); if (fileBytes == null) { return(NotFound("当前的文件信息不存在")); } return(File(fileBytes, file.FileType, file.FileName)); }
public async Task UpdateProfilePictureAsync(UpdateProfilePictureInput input) { byte[] byteArray; var imageBytes = _dataTempFileCacheManager.GetFile(input.FileToken); if (imageBytes == null) { throw new UserFriendlyException("没有找到符合这个图片的token信息: " + input.FileToken); } using (var bmpImage = new Bitmap(new MemoryStream(imageBytes))) { var width = (input.Width == 0 || input.Width > bmpImage.Width) ? bmpImage.Width : input.Width; var height = (input.Height == 0 || input.Height > bmpImage.Height) ? bmpImage.Height : input.Height; var bmCrop = bmpImage.Clone(new Rectangle(input.X, input.Y, width, height), bmpImage.PixelFormat); using (var stream = new MemoryStream()) { bmCrop.Save(stream, bmpImage.RawFormat); byteArray = stream.ToArray(); } } if (byteArray.Length > MaxProfilPictureBytes) { throw new UserFriendlyException(L("ResizedProfilePicture_Warn_SizeLimit", AppConsts.ResizedMaxProfilPictureBytesUserFriendlyValue)); } var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId()); if (user.ProfilePictureId.HasValue) { await _dataFileObjectManager.DeleteAsync(user.ProfilePictureId.Value); } var storedFile = new DataFileObject(AbpSession.TenantId, byteArray); await _dataFileObjectManager.SaveAsync(storedFile); user.ProfilePictureId = storedFile.Id; }