src/SSCMS.Web/Controllers/Home/ProfileController.Upload.cs
(完整代码) 1KBusing System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SSCMS.Configuration;
using SSCMS.Dto;
using SSCMS.Utils;
namespace SSCMS.Web.Controllers.Home
{
public partial class ProfileController
{
[RequestSizeLimit(long.MaxValue)]
[HttpPost, Route(RouteUpload)]
public async Task<ActionResult<StringResult>> Upload([FromForm] IFormFile file)
{
if (file == null) return this.Error(Constants.ErrorUpload);
var fileName = _pathManager.GetUploadFileName(file.FileName);
var filePath = _pathManager.GetUserUploadPath(_authManager.UserId, fileName);
if (!FileUtils.IsImage(PathUtils.GetExtension(fileName)))
{
return this.Error(Constants.ErrorImageExtensionAllowed);
}
await _pathManager.UploadAsync(file, filePath);
var avatarUrl = _pathManager.GetUserUploadUrl(_authManager.UserId, fileName);
return new StringResult
{
Value = avatarUrl
};
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
