I'm using a custom written auto uploader to import images from users to Amazon S3
. I'm building up a parallel image library
in my database, so I know what images I can access on S3 to not waste any http-requests.
However, my uploader sometimes throws errors (e.g. source image missing) and although I'm validating, I'm sometimes ending up with entries in my media table and no matching image on S3.
To correct these, I'm thinking of creating a cfthread
/cfschedule
which clears my image database from faulty entries. What I'm not sure is how to capture 404 responses
. Right now I'm having this on a page:
<img src="#variables.imageSrc#" alt="#some alt#" title="#some title#" class="ui-li-thumb ui-corner-all" />
which tries to load the image and returns a 404 if not successful.
Question
How would I capture this 404
? I don't want to put anything in the markup, so I assume this should go to onrequestend
or another Coldfusion event being monitored in my application.cfc
. If so, is there an easy way to identify image request, because I would not want to run a big routine on every applicationr request.
Thanks for insights!
EDIT:
I don't think running isDefined
on every image before displaying it is feasable, because it will be a double request to S3 and there is a lot of images. I want to take the 404 and then clean up my database, so next time the image will not be accessed anymore.