7.1.7 • Published 4 months ago

@uploadthing/nuxt v7.1.7

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Nuxt UploadThing Module

npm version npm downloads License Nuxt

Nuxt module for getting started with UploadThing in your Nuxt app.

Quick Setup

  1. Add @uploadthing/nuxt and uploadthing dependencies to your project
# Using pnpm
pnpm add -D @uploadthing/nuxt
pnpm add uploadthing

# Using yarn
yarn add --dev @uploadthing/nuxt
yarn add uploadthing

# Using npm
npm install --save-dev @uploadthing/nuxt
npm install uploadthing

# Using bun
bun add -D @uploadthing/nuxt
bun add uploadthing
  1. Add @uploadthing/nuxt to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: ["@uploadthing/nuxt"],
});

That's it! You can now use @uploadthing/nuxt in your Nuxt app ✨

Usage

For full documentation, see the UploadThing docs

  1. Create an upload router in your app:
// server/uploadthing.ts
import { createUploadthing, UTFiles } from "uploadthing/h3";
import type { FileRouter } from "uploadthing/h3";

const f = createUploadthing();

/**
 * This is your Uploadthing file router. For more information:
 * @see https://docs.uploadthing.com/api-reference/server#file-routes
 */
export const uploadRouter = {
  videoAndImage: f({
    image: {
      maxFileSize: "4MB",
      maxFileCount: 4,
      acl: "public-read",
    },
    video: {
      maxFileSize: "16MB",
    },
  })
    .middleware(({ event, files }) => {
      //           ^? H3Event

      // Return some metadata to be stored with the file
      return { foo: "bar" as const };
    })
    .onUploadComplete(({ file, metadata }) => {
      //                       ^? { foo: "bar" }
      console.log("upload completed", file);
    }),
} satisfies FileRouter;

export type UploadRouter = typeof uploadRouter;
  1. Mount a component in your app and start uploading files:
<script setup lang="ts">
const alert = (msg: string) => {
  window.alert(msg);
};
</script>

<template>
  <div>Playground</div>
  <UploadButton
    :config="{
      endpoint: 'videoAndImage',
      onClientUploadComplete: (res) => {
        console.log(`onClientUploadComplete`, res);
        alert('Upload Completed');
      },
      onUploadBegin: () => {
        console.log(`onUploadBegin`);
      },
    }"
  />

  <UploadDropzone
    :config="{
      endpoint: 'videoAndImage',
      onClientUploadComplete: (res) => {
        console.log(`onClientUploadComplete`, res);
        alert('Upload Completed');
      },
      onUploadBegin: () => {
        console.log(`onUploadBegin`);
      },
    }"
  />
</template>

Wow, that was easy!

Development

From workspace root:

# Install dependencies
pnpm install

# Develop with the playground
pnpm dev

# Run ESLint
pnpm lint
7.1.7

4 months ago

7.1.6

4 months ago

7.1.5-canary.63144

6 months ago

7.1.5

6 months ago

7.1.4

6 months ago

7.1.3

6 months ago

7.1.2

6 months ago

7.1.1

7 months ago

7.1.0

8 months ago

7.0.3

8 months ago

6.5.10

9 months ago

7.0.0

9 months ago

7.0.2

9 months ago

7.0.1

9 months ago

6.5.8

12 months ago

6.5.7

12 months ago

6.5.9

12 months ago

6.5.6

1 year ago

6.5.5

1 year ago

6.5.4

1 year ago

6.5.3

1 year ago

6.5.2

1 year ago

6.5.1

1 year ago

6.5.0

1 year ago