Here’s a simple example of how to use the Restash client SDK to upload files directly from the browser.
Copy
import { createRestashUploader } from "@restash/client";// create the uploader with your public API keyconst upload = createRestashUploader({ publicKey: "pk_123456789",});// can be a file or a blobconst file = new File(["test"], "test.txt", { type: "text/plain",});const result = await upload(file);console.log(result.url); // https://cdn.restash.io/{result.key}
If your team has signature enforcement enabled, you need to generate a signature for each upload request. You can do this by creating a server route that returns a signature and payload
using the generateSig function from the Restash client SDK. Generating signatures needs to be done on the server. You can then pass this route to the createRestashUploader so that it can be called when needed.