Skip to content

File Operations in oRPC

oRPC natively supports file uploads and downloads using standard File and Blob objects, requiring no additional configuration.

TIP

For files larger than 10MB, it is recommended to use a dedicated solution for performance and reliability.

Validation

oRPC uses the standard File and Blob objects to handle file operations. To validate file uploads and downloads, you can use the z.instanceof(File) and z.instanceof(Blob) validators, or equivalent schemas in libraries like Valibot or Arktype.

ts
const 
example
=
os
.
input
(
z
.
object
({
file
:
z
.
instanceof
(
File
) }))
.
output
(
z
.
object
({
file
:
z
.
instanceof
(
File
) }))
.
handler
(async ({
input
}) => {
console
.
log
(
input
.
file
.
name
)
return {
file
:
input
.
file
}
})

INFO

If you are using Node.js 18, you can import the File class from the buffer module.

Released under the MIT License.