添加项目文件。

This commit is contained in:
2026-10-12 16:22:04 +08:00
parent 7c68a0ca0a
commit aad11be43d
1000 changed files with 120807 additions and 0 deletions
@@ -0,0 +1,40 @@
using Common;
using Microsoft.AspNetCore.Mvc;
namespace CustomerApi.Controllers
{
[Route("customerapi/[controller]")]
[ApiController]
public class ImageUploadController : ControllerBase
{
public class ImageUploadResponse
{
public string Path { get; set; } = "";
}
[HttpPost("upload")]
public async Task<BaseResponse<ImageUploadResponse>> UploadFile(IFormFile file)
{
if (file == null || file.Length == 0)
{
return new BaseResponse<ImageUploadResponse>
{
Code = CommonResponseCodeEnum.ParamError,
Info = "No file uploaded."
};
}
var guid = Guid.NewGuid().ToString("N");
var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/uploads", guid + Path.GetExtension(file.FileName));
using (var stream = new FileStream(path, FileMode.Create))
{
await file.CopyToAsync(stream);
}
return new BaseResponse<ImageUploadResponse>
{
Code = CommonResponseCodeEnum.Success,
Info = "上传成功",
Data = new ImageUploadResponse { Path = $"uploads/{guid + Path.GetExtension(file.FileName)}" }
};
}
}
}