Skip to content

Files

Latest commit

8e90b6a · Apr 17, 2023

History

History
27 lines (21 loc) · 607 Bytes

README.md

File metadata and controls

27 lines (21 loc) · 607 Bytes

kozy

Next 13 FormData image upload tool via API route

npm i kozy
yarn add kozy
pnpm add kozy

It is very easy to use. After installing the package, create a route called upload under the api folder and add the following code.

export async function POST(req: NextRequest, res: NextResponse) {
  const form: any = await req.formData();
  const file = form.get('avatar');

  const uploaded: any = await UploadImage({
    file,
    folder: 'uploads',
    name: `hello_world`,
    size: '2 MB',
  });

  return NextResponse.json({ data: uploaded.file, isSuccess: true });
}