本文整理汇总了C#中IFormFile.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# IFormFile.CopyTo方法的具体用法?C# IFormFile.CopyTo怎么用?C# IFormFile.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormFile
的用法示例。
在下文中一共展示了IFormFile.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateLogoAsync
public async Task<string> UpdateLogoAsync(int? clubId, IFormFile file)
{
string path = string.Empty;
if (clubId.HasValue)
{
path = await _clubService.GetNameAsync(clubId.Value);
}
var relativePath = path;
if (string.IsNullOrEmpty(path) || !path.Contains(LogoPath))
{
var newName = (string.IsNullOrWhiteSpace(path) ? GenerateNewName() : path) + "." + file.FileName.Split('.').Last();
var newPath = GenerateNewPath(LogoPath);
relativePath = Path.Combine(newPath, newName);
path = GetFullPath(relativePath);
}
else
{
path = GetFullPath(path);
}
file.CopyTo(new FileStream(path, FileMode.Create));
relativePath = Regex.Replace(relativePath, "\\\\", "/");
if (clubId.HasValue)
{
await _clubService.UpdateLogoAsync(clubId.Value, relativePath);
}
return relativePath;
}
示例2: UpdateAvatarAsync
public async Task<string> UpdateAvatarAsync(int userId, IFormFile file)
{
var path = await _userService.GetPhotoPathAsync(userId);
var relativePath = path;
if (string.IsNullOrEmpty(path))
{
var newName = GenerateNewName() + "." + file.FileName.Split('.').Last();
var newPath = GenerateNewPath(AvatarPath);
relativePath = Path.Combine(newPath, newName);
path = GetFullPath(relativePath);
}
else
{
path = GetFullPath(path);
}
file.CopyTo(new FileStream(path, FileMode.Create));
relativePath = Regex.Replace(relativePath, "\\\\", "/");
await _userService.UpdatePhotoPathAsync(userId, relativePath);
return relativePath;
}