No callback from Images for when a direct upload is complete?

I'm building a product that uses Images' direct upload feature. I need to be able to return images based on which user owns them, so I need to store them in a database because the Images API only allows for listing images, not filtering by metadata. As direct uploads have no event or callback on completion, I have to add a database entry on creation of the direct upload link. This means I have lots of potentially redundant entries that I have to sift through and check if they finished or failed uploading. Surely there's a better way to know when an image has been uploaded?
2 Replies
Chaika
Chaika13mo ago
You could just simply have the user call an endpoint to tell your server the upload is complete, and your server checks it. Using expiry (or just leaving the default of 30 minutes), you'd know that any uploads which haven't been told they were completed & checked have been abandoned after 30 minutes. Or you could just proxy the image upload through your server or a Worker entirely, they're not too large. You can stream it through the Worker to the normal upload: https://developers.cloudflare.com/api/operations/cloudflare-images-upload-an-image-via-url and then have it call your api on success. If the user cancelled the upload, it would cancel the request before it calls your API (ex. Don't create any DB entry until its confirmed uploaded)
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
poro
poro12mo ago
An upload completion hook that a worker could catch up would be great for my usecase.
Want results from more Discord servers?
Add your server