Skip to content

Accessing binding variable name in wrangler.toml inside functions #93

@rohanbam

Description

@rohanbam

I want to access an r2 bucket from a vitedge function.
Cloudflare docs state that in order to access r2 bucket from a worker, it is necessary to bind worker to r2 bucket using the following syntax inside wrangler.toml

r2_buckets = [
{
binding = "BUCKET-1",
bucket_name = "bucket-1",
preview_bucket_name = "bucket-1"
},
{
binding = "BUCKET-2",
bucket_name = "bucket-2",
preview_bucket_name = "bucket-2"
}
]

and then, use that binding inside the worker as follows
const object = await env.Bucket1.get(objectName, ...)

however, in the above line env is undefined inside vitedge functions.

can you provide an example of how this binding variable can be accessed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions