Postgres - lo_import - import user’s machine directory image

Asked

Viewed 76 times

0

I have an application that stores the photo of a product - it is in a table separates from the main table

CREATE TABLE produtos_imagem
(
    registro integer NOT NULL,
    imagem oid,
    CONSTRAINT produtos_pkey PRIMARY KEY (registro)
)
WITH (
    OIDS = TRUE
)
TABLESPACE pg_default;

Running the command to import the image works perfectly on the development machine that has the local postgres server. for example

INSERT INTO produto_imagem(registro, imagem) VALUES (4255, lo_import('C:\\temp\\monitor.bmp'));

where C: temp would be a directory on the user’s machine

if I execute this command on the postgres server base error occurs:

ERRO:  não pôde abrir arquivo "C:\temp\monitor.bmp" no servidor: Arquivo ou diretório não encontrado

********** Error **********

ERRO: não pôde abrir arquivo "C:\temp\monitor.bmp" no servidor: Arquivo ou diretório não encontrado
SQL state: 58P01

it seems to me that postgres tries to fetch the image in the server directory and not in a directory of the user’s machine.

has some way to inform the server that the directory must be on the local machine?

1 answer

0

Really command INSERT runs on the server and it assumes that the file resides on the server.

To send a file resident on the client machine to the server use, for example. the command \lo_import filename [ comment] of psql.

https://www.postgresql.org/docs/current/app-psql.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.