Assuming that you don't need to transform the image (say, via some PostGIS-specific API), this is exactly what the PostgreSQL large object API is for.
You haven't mentioned the programming language you're using, so it's rather hard to be more detailed. Assuming you're using C, you can use libpq
's lo_write
, etc. See large objects in the manual.
If that won't cut it, you might have to open a pipe to the raster2pgsql
tool and do a streaming write. Not all programs can cope with reading from a pipe, some need random access to the file, and in that case you're probably stuck with writing a temp file. A quick look at the raster2pgsql
docs suggest that it just writes out SQL, so take a look at the SQL code it generates. See if you can link to it as a library and use it inside your code, or adapt it to read from a pipe. You could even create a shared memory region accessible as a file (on UNIX) and point it at that.
I suspect you'll land up using the GDAL library to do the same work raster2pgsql
does inside your app.
(BTW, for the PostGIS-specific side of things you might have more luck on http://gis.stackexchange.com/)