Count how many times a r2 file has been viewed/downloaded with GET req's

Hi!
I'm currently working on a a feature that allows user to enable auto-deletion of files if the image has been viewed less than x amount of times over a certain period.

All I really want to do in my worker is to listen to a GET req from any file in my bucket and and simply increment a counter in my database with the image url/id. Then I'll spin up a cron job on Vercel which handles the deletion.

I have currently only made a binding between my worker and my r2 bucket, and I tried a simple test with just redirecting any requests back to my homepage, but when I try to access a file in my bucket, it shows the image, instead of redirecting, and nothing is logged either.

Am I thinking about this the wrong way? Are these requests only on the worker url, and in that case, should I move my entire uploading logic to the worker, instead of having it running on a separate Go server?
Was this page helpful?