Use Byte[] instead of File for DTO

This commit is contained in:
2025-06-28 11:03:16 -07:00
parent c08cf9ff43
commit dbf9ad464c
5 changed files with 36 additions and 26 deletions
@@ -57,9 +57,21 @@ namespace MistoxWebsite.Server.Controllers {
[Route( "api/product/create" )]
[HttpPost]
public async Task<ActionResult<bool>> CreateProduct( [FromBody] Product obj ) {
public async Task<ActionResult<bool>> CreateProduct([FromForm] Product obj, [FromForm] List<IFormFile> images){
try {
await _databaseService.NewProduct( obj );
List<ProductImage> building = new List<ProductImage>();
foreach (var file in images) {
using (var stream = new MemoryStream()) {
await file.CopyToAsync(stream);
var bytes = stream.ToArray();
// Convert to your image model or whatever your logic is
ProductImage img = new ProductImage { Image = bytes, Name = file.FileName };
building.Add(img);
}
}
obj.Images = building.ToArray();
await _databaseService.NewProduct(obj);
await UpdateStore();
return true;
} catch {