Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image upload - Where to put code using CQRS and DDD

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?

like image 657
user17245 Avatar asked Jan 18 '26 11:01

user17245


1 Answers

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)
like image 164
amig0 Avatar answered Jan 20 '26 01:01

amig0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!