What is the correct order to put files in S3 and update DB ?

I am doing something very simple. I need to update some content which has images. What is the correct order of doing the update: 1) optimistic - send update mutation to api (I am using rest but trpc will replace it soon*) api update the content on db and send back put urls for client - client then use those urls to put stuff it S3 advantage: less api calls disadvantage: not sure if things actualy exist in S3 2) controlled - request put urls - client then use those urls to put stuff it S3 - send update mutations with correct access avantage: less likely that the file doesn't exist in S3 disadvantages: more calls and client could put stuff in S3 and never update db
2 Replies
Neto
Neto2y ago
i like doing - creating one or more signed url, and sending to the client - client uploads - client send the s3 key to be stored in the db is not that hard to construct a s3 url you can just send the full url back and receive it back on the next request
JulieCezar
JulieCezar2y ago
https://discord.com/channels/966627436387266600/1068803756298346556/1070097148554780673 I answered this a while ago and made a demo repo It's with DigitalOcean Spaces, but it's mostly the same as with AWS S3
Want results from more Discord servers?
Add your server