1.0.3 • Published 7 months ago

@restash/client v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@restash/client

The official Restash client for uploading files directly from the browser.

Installation

npm install @restash/client

Quickstart

Upload files directly from the browser to Restash.

import { createRestashUploader } from "@restash/client";

const upload = createRestashUploader({ publicKey: "pk_..." });

const result = await upload(file, {
  path: "uploads/", // optional directory to upload to
  onProgress: ({ percent }) => {
    console.log(`Uploading... ${percent}%`)
  },
});

console.log("File uploaded:", result.url);

If your team requires signed uploads

Create a route to generate signatures using the generateSig function with your secret key

import { generateSig } from "@restash/client";

const { payload, signature } = generateSig(process.env.RESTASH_SECRET_KEY!);

return NextResponse.json({ payload, signature });

Then pass your signature route to the createRestashUploader function:

const upload = createRestashUploader({
  publicKey: "pk_...",
  handleSignature: "/api/restash/signature",
});

Do not call generateSig from the browser - this requires your secret key and must be executed in a server environment only.

More coming soon

  • React hooks
  • Uploader components
  • File picker
  • More...

Feedback & Support

Have questions or feature requests? Drop an issue on Github

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago