Use Byte[] instead of File for DTO
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user