putting Image from database in cgi app

Steve Holden sholden at holdenweb.com
Wed May 21 11:11:27 EDT 2003


"Gerhard Häring" <gh at ghaering.de> wrote in message
news:mailman.1053528864.20607.python-list at python.org...
> Gerhard Häring wrote:
> > Fredrik Lundh wrote:
> >
> >> Gerhard Häring wrote:
> >>
> >>> In the end, using the temp file is probably the easiest solution, at
> >>> least as long as the web technology you use is CGI.
> >>
> >>
> >> and you never have more than one visitor at a time, or don't care
> >> if people don't get the right cover...
> >
> >
> > How would that be a problem? Just create a unique name for the temp
> > file, put in a directory, like, say "cache/" and have a cron job that
> > periodically deletes old temp files.
> >
> > Are there possible circumstances where that approach would be
problematic?
>
> Apart from the obvious DoS vulnerability ;-)
>

It would also be a good idea to maintain a "cached" attribute in the
database, and the file's path in the cache, so you knew which images were
already in filestore. A background process could clean up the cache (and the
corresponding database rows) periodically. No point extracting images from
the database more often than necessary.

Perhaps you're beginning to wish you'd just stored the path in the database
is the first place? Not always the best solution, but usually worth
considering when the database structure is under your control.

I once worked with a guy who was supposed to be writing a web system to
track software downloads using Oracle. He spent about three weeks hacking
away at C code to store the installers, which could be up to 100MB in size,
in the database as blobs.

When I asked him why he'd chosen to do this all I got was a blank stare and
a lot of handwaving: when a user needed to download the installer he was
extracting it from the database and passing an FTP URL to the cached copy to
effect the download.

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/







More information about the Python-list mailing list