Ok, reading the PostgreSQL documentation on blobs helped :)
From what I can tell, there is no way to write a blob directly;
from a scalar; instead you have to use the lo_import and lo_export
methods with disk-based files, the way you are doing it now.
As much as MySQL gets picked on for not being a "real" RDBMS, it
seems a lot better suited for what you want to do here than PostgreSQL.