What’s the best practice here?
Understand there’s some limitations and I’m experimenting and getting no where. I appreciate anyone’s help. Some code / context below (note, none of these are right and more trying to illustrate the issues…):
It seems the following doesn’t work and strips the File data:
// I strip the File data so all you get is name="file_title.png" const formData = await request.formData()
Okay, so lets try something harder:
// I strip the name and mime type... const formData = await request.arrayBuffer() // Try to rebuild... var rebuiltDataisThisEvenPossible = base64CrazyFunctionOrPolyFillMagic(formData);
So finally why not just copy name/mimetype ideas from it KV Asset Handler and base it on the route:
// GET cat.png run_kv_asset_handler_code() // POST cat.png let fileName = request.url.pathname // (not real code, none of this works) let catUpdate = await KV_DEMO.put(fileName, await request.arrayBuffer()) console.log(catUpdate) return new Response('check console')
- What’s the best practice for storing images/files in Cloudflare KV?
- Limitations to getting Files from POST exist. If a Polyfill direction 1 or 2 rebuilding the ArrayBuffer to Base64 can potentially work, does anyone have an example of this? Is CPU time limts going to be an issue?
- Currently sending images as Base64 pre-coded is my plan. Bringing this to the worker though would be awesome…
Disclosure: I am noob… Any dead-simple code is appreciated. Apologize if this is all over town