Yeah, that was v2, but it got rolled back a while ago
Yeah, that was v2, but it got rolled back a while ago
env.KV_BINDING.put("imagename", request.body)const image = env.KV_BINDING.get("imagename", { type: "stream" }); (notice the stream part to get back as a stream)file.readable I think?
list only shows you the keys. You need to run get on each key to get the image.

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