jasontaylordev / NorthwindTraders

Northwind Traders is a sample application built using ASP.NET Core and Entity Framework Core.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request] File Upload

kevinleptin opened this issue · comments

In my understanding, adding a uploading file feature will make the Northwind project more perfect.

@kevinleptin - Would you like to see file uploading into cloud or local (for example wwwroot/uploads)? Any restrictions like ONLY PHOTOS or something else? Be more precise 🚀

Local (wwwroot/uploads) first!
:)

I have a problem about update file feature (wwwroot/uploads). I want to bind IFormFile interface to my ViewModel so where my ViewModel should be placed, Presentation or Application layer?

I have a problem about update file feature (wwwroot/uploads). I want to bind IFormFile interface to my ViewModel so where my ViewModel should be placed, Presentation or Application layer?

In my humble opinion you should use IFormFile only in presentation layer and pass Streams into app. Here I've prepared for you how can it look (of course you can disagree with me). You can add some validation before of course:

public class UploadsController : BaseController
  {
    [HttpPost]
    public async Task<IActionResult> Upload()
    {
      var file = Request.Form.Files[0];
      var request = new UploadPhotoCommand(file.FileName, file.OpenReadStream());
      var url = await Mediator.Send(request);
      return Ok(new { url });
    }
  }

Thanks for the question. This would make a good feature, especially for uploading employee photos and category images. I really like @rafalschmidt97 's approach, recommend following it. I've added this to the roadmap, so I'll try to add an example in the future. Thanks.