Fitim Bytyqi
Fitim Bytyqi3mo ago

Blob as response

I know this has been mentioned couple of time but does TRPC allow returning a blob on the client from a publicProcedure.
downloadFile: baseProcedure.mutation(async () => {
const response = await ky("api/export", {
headers: {
Authorization: `Bearer ${(await cookies()).get("token")?.value}`,
},
}).blob();

return response;
}),
downloadFile: baseProcedure.mutation(async () => {
const response = await ky("api/export", {
headers: {
Authorization: `Bearer ${(await cookies()).get("token")?.value}`,
},
}).blob();

return response;
}),
This works when used with server actions from this blog https://trpc.io/blog/trpc-actions I wanted to ask if that's the case with publicProcedures too.
5 Replies
Alex / KATT 🐱
not currently how would you expect it to work? can you maybe show me some frontend code on how you would like to use it?
Fitim Bytyqi
Fitim BytyqiOP3mo ago
I will send a screenshot on how I made it work via server actions a bit later
Fitim Bytyqi
Fitim BytyqiOP3mo ago
I would expect this to work, but not sure if this is even possible.
No description
No description
Alex / KATT 🐱
currently you'd have to base64-encode the blob since we only support json but thanks for sharing it, we do want to support this sort of thing in the future
Fitim Bytyqi
Fitim BytyqiOP3mo ago
alright, thanks a lot for your help, indeed this would be nice, beside this, being able to use server actions in such manner would be great too. Like trpc.users.blockuser.useMutation where blockuser is a server actions

Did you find this page helpful?