```tsx export async function POST(req: NextRequest) { const formData = await req.formData(); con

export async function POST(req: NextRequest) {
  const formData = await req.formData();
  const file = formData.get("file") as File;
  console.log(file);
  console.log(file.type);
  console.log(file.name);
  // check if incoming data is a file and an image extension
  if (!file || !file.type.startsWith("image/")) {
    return new Response(JSON.stringify("error"), {
      headers: {
        "content-type": "application/json",
      },
    });
  }

  // if it is a file, upload the name of it to KV
  const { GALLERY } = process.env;
  const response = await GALLERY.put(file.name, file as unknown as ReadableStream<Uint8Array>);

  return new Response(JSON.stringify(response), {
    headers: {
      "content-type": "application/json",
    },
  });
}


I'm new to using KV/next on pages, I seem to be getting the type error that GALLERY.put is not a function. But it does exist and I'm pretty sure it would work on production but I am testing locally now using npx cf-bindings-proxy
Was this page helpful?