Huge Letters
Huge Letters
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Huge Letters on 3/8/2024 in #questions
onUploadComplete and onUploadError
Do I understand correctly that throwing error in onUploadComplete won't trigger onUploadError? I just need to return errors as values from onUploadComplete and check manually in onClientUploadComplete?
3 replies
TTCTheo's Typesafe Cult
Created by Huge Letters on 10/22/2023 in #questions
What to store on my server?
What's the usual pattern to store references to UT-files in my database? I store file keys since then using the key I can make a request to UT to get file url. Is that how most people do it? Or actually you should store urls directly? In that case I don't really understand how can I delete files w/o doing some complicated and bloated checks
7 replies
TTCTheo's Typesafe Cult
Created by Huge Letters on 9/6/2023 in #questions
Await server onUploadComplete hook on the client.
Is there a way or a recommended pattern to run some side effect in the onUploadComplete hook in UT router and only once it's done resolve startUpload promise on the client? In my app a user can leave a review with an image attached - first client sends a request with review data and it gets saved to the database, once that resolves client starts an image upload and in the onUploadComplete hook on the server I update the db review row with a newly created file key. Problem is - I would like to refetch review data on the client to sync it with the server once data is successfully updated. But there doesn't seem to be a mechanism to await until onUploadComplete resolves and so what I got is a race condition if a client's sync request will be after(good) or before(bad) hook updates my db with new file key. Code more or less looks like this.
// client
await postReview(review);
await uploadImage(image);
sync(); // <- I would like this to run only after updateReview on the server finishes

// server - UT router
.middleware(...)
.onUploadComplete(async ({ file, metadata: { data } }) => {
await updateReview(data, file);
}),
// client
await postReview(review);
await uploadImage(image);
sync(); // <- I would like this to run only after updateReview on the server finishes

// server - UT router
.middleware(...)
.onUploadComplete(async ({ file, metadata: { data } }) => {
await updateReview(data, file);
}),
1 replies