/// <summary> /// 上传文件 /// </summary> public async Task <string> AddWorkFlowInstanceFormFile(IFormFile file) { var endfix = file.FileName.Split('.').Last(); var newName = Path.Combine(DateTime.Now.ToString("MMddHHmmssfff") + '.' + endfix); await _fileStore.CreateFile(newName, _serverFileRootPath, file.OpenReadStream()); return(newName); }
/// <summary> /// 更新用户头像 /// </summary> /// <param name="userId">用户ID</param> /// <param name="formFile">表单头像文件</param> /// <returns></returns> public async Task <string> UpdateUserAvatarAsync(Guid userId, IFormFile formFile) { // 生成新文件名 var endfix = formFile.FileName.Split('.').Last(); var newName = Path.Combine(DateTime.Now.ToString("MMddHHmmssfff") + '.' + endfix); // 可以替换成其他的文件保存方式,当前是直接利用静态文件目录的方式保存到服务器磁盘上。 await _fileStore.CreateFile(newName, _serverFileRootPath, formFile.OpenReadStream()); var user = await _userManager.FindByIdAsync(userId.ToString()); // 删除旧头像 _fileStore.DeleteFile(user.Avatar, _serverFileRootPath); user.Avatar = newName; await _userManager.UpdateAsync(user); return(newName); }
public async Task <Guid> Handle(CreateRecipePicture request, CancellationToken cancellationToken) { return(await _store.CreateFile(request.Content)); }