Learn how to upload files from your server to Restash.
Easily upload files from a Node.js server to Restash.
This guide shows you how to set up server-side uploads using our lightweight SDK.
You can only upload files up to 4MB on the server. If you want to upload files larger than 4MB,
you can use the client side SDK to upload files directly from the browser.
In this example, we will upload a file inside a Next.js API route.
api/upload/route.ts
Copy
import { NextResponse, NextRequest } from "next/server";import { restash } from "@/lib/restash";export const POST = async (req: NextRequest) => { const formData = await req.formData(); const file = formData.get("file") as File; const upload = await restash.files.upload(file); // store the upload in your db or do something else with it console.log(upload.url); return NextResponse.json(upload);};