Add getMiniflareR2Bucket helper method - R2 Helper method
By adding the helper method getMiniflareR2Bucket one can get a bucket just by:
const bucket = await getMiniflareR2Bucket('BUCKET');
without having to create a new Miniflare instance
global.getMiniflareR2Bucket = async (bucket) => {
const plugin = (await mf.getPlugins()).R2Plugin;
const storage = mf.getPluginStorage("R2Plugin");
return plugin.getBucket(storage, bucket);
}
My fault. When working on R2, I added 0 support for jest in the initial PR 😵💫 . Thanks for pointing this out!
You are kidding right? You did an awesome work!
Do you have any idea of how much you helped me out?
Besides, this is a minor thing!
Hey! 👋 Apologies for the delayed response. I've recently returned from a long holiday and am just starting to catch up on issues now.
I don't actually think we need this. You can add an R2 bucket binding using the standard r2_buckets/r2Buckets option, then access them globally, or using the existing getMiniflareBindings method. I think this would be better suited to user code if needed. Let me know if I'm missing something.
Hi, welcome back!
I hope your holidays were awesome!
You are quite right! I'm so sorry!
I'm guessing you mean something like this instead:
env.MY_BUCKET.put(key, request.body);
I was using a TDD mindset so when I got to this part, I was thinking on testing and used the sample in the Miniflare R2 documentation as starting point.
Only latter did I went on to use the R2 Bucket directly, and to be honest, I haven't thought about this since.
Thank you all!
No worries! Yep, that's what I was thinking of. 🙂