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",
},
});
}
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",
},
});
}