brocoders / nestjs-boilerplate

NestJS boilerplate. Auth, TypeORM, Mongoose, Postgres, MongoDB, Mailing, I18N, Docker.
https://nestjs-boilerplate-test.herokuapp.com/docs
MIT License
2.98k stars 598 forks source link

How user's photo is send to s3? #1151

Closed willianspraciano closed 1 year ago

willianspraciano commented 1 year ago

It's not a bug but a question, could you explain to me how is the user's photo (which is a FileEntity) sent to s3? Additionally, could you clarify how it is deleted if I update the photo?

My doubt is why, from what I've seen in the users.service file, it doesn't use the files.service

Shchepotin commented 1 year ago

@willianspraciano

could you explain to me how is the user's photo (which is a FileEntity) sent to s3

Upload files to S3 via multerS3 here

https://github.com/brocoders/nestjs-boilerplate/blob/db725ab58669f84aede30158a298dd48cbe744cb/src/files/files.module.ts#L49-L67

Additionally, could you clarify how it is deleted if I update the photo?

We prefer not to delete files, as this may have negative experience during restoring data. Also for this reason we also use Soft-Delete approach in database. However, if you need to delete files you can create your own handler, cronjob, etc.

More info about uploading files you can find here: https://github.com/brocoders/nestjs-boilerplate/blob/main/docs/file-uploading.md

willianspraciano commented 1 year ago

@Shchepotin Thank you for the clarification. I hadn't noticed that link to the Full Documentation in my initial read of the README. It makes a lot of sense. I was thinking that the user service would handle the creation of the File itself, but in this case, a file is first created and then this already created file is sent to the user. It's a great implementation, congratulations.