trigger.dev
trigger.dev copied to clipboard
[TRI-4135] Add support for Blob in payloads and outputs.
We use SuperJSON so you can use types beyond regular JSON in your payloads/outputs. It would be great to add Blob to this.
The source code is here: https://github.com/triggerdotdev/trigger.dev/blob/f7bf7bc2687e984655436592dd65a154e0c56dc5/packages/core/src/v3/utils/ioSerialization.ts#L419
@matt-aitken here's what I tried for adding Blob to SuperJSON
superjson.registerCustom<Blob, number[]>(
{
isApplicable: (v): v is Blob => typeof Blob === "function" && v instanceof Blob,
serialize: async (v) => {
const arrayBuffer = await v.arrayBuffer();
return [...(new Uint8Array(arrayBuffer))];
},
deserialize: (v) => {
const u8Array = new Uint8Array(v);
const arrayBuffer = u8Array.buffer.slice(u8Array.byteOffset, u8Array.byteOffset + u8Array.byteLength);
return new Blob([arrayBuffer]);
},
},
"blob"
);
but unfortunately serialize function cannot return promise and Blob cannot be serialized synchronously. Would you consider other approach for this?