Graham Dumpleton
grahamd at dscpl.com.au
Sun Jul 2 18:16:32 EDT 2006
webograph wrote .. > hi, > > i'm currently implementing a server that provides downsampled and > cropped versions of available images. > the idea is to have a regular directory structure and a python handler > that does (in pseudocode): > > if exists(requested_file): > return apache.DECLINED > > image=open(original(requested_file)) > image=image.scale_down() > image.save(requested_file) > > return apache.DECLINED > > the problem is that i always get a 404 when i request a file that has > just been created; it's not a timing problem. > > i've solved it using a req.internal_redirect, but i don't think that > that is the ideal solution The short answer is to use req.sendfile() to have your handler respond with the actual content of the file. You will need to ensure you set any appropriate content type before making the call though. Thus your code might read: if not exists(requested_file): image=open(original(requested_file)) image=image.scale_down() image.save(requested_file) req.content_type = "..." req.sendfile(requested_file) return apache.OK Returning apache.DECLINED in order to have Apache default handler return the file may not be the most reliable way of doing things especially when the file didn't exist before hand and if MultiViews is enabled and comes into play. Graham
|