delta
CDCloudflare Developers
•Created by delta on 2/28/2025 in #workers-help
TypeError: Illegal invocation: function called with incorrect this reference
I got this error when calling some method from generated api client.
when class looks like this:
and doing
(new API()).callMethod()
will raise the error.
after some searching, I found different context makes this problem and this can be solved by passing fetch to fetch.bind(globalThis)
, which binds fetch's context to global context.
What I don't understand yet is why API works on browser and node, but Worker needs to bind globalThis to fetch.1 replies
CDCloudflare Developers
•Created by delta on 8/5/2024 in #workers-help
verify r2 upload using hash
I'm trying to implement a user file upload system with hash and size verification, along with streaming uploads to R2. The challenge I'm facing is that Workers have a 128MB memory limit, so I can't buffer the entire request. so I need to stream the upload to R2, but I'm struggling to find a way to cancel the upload if hash unmatched or size is not correct.
Any suggestions on how to approach this would be really helpful. Thank you!
2 replies