2
votes

I would like to know the best way to upload a file using DDD and CQRS. I would like to save the image in my files, and save the name in database.

PS: I know that DDD is not about many layers project.

This is my example:

Customer (Id, Name, Email, Picture (only one))

I'm not asking the code to save the image. But where to call the save image method.

In Controller, I have a CustomerViewModel with these fields. After that, I call my Application Layer, with CustomerAppService, then a Command... and so on...

The method of saving images in folder is in my infrastructure layer.

Should I call the save in folder method in Controller? In Application? In CommandHandler?

2

2 Answers

1
votes

Based on my experience I solved the issue like:

  1. Create endpoint (controller action) to generate temporary link for uploading file directly to the storage (we used AWS S3 and it provides the ability to create pre-signed url)
  2. Client uploads files by the url
  3. Client sends acknowledge request with metadata to another endpoint (controller action)
0
votes

You can save the image in the Controller and retain a reference to the saved file, e.g. a path, an ID of a record in a database, an S3 bucket address, etc. That reference is what you would pass in your command and would be saved on the Customer record.