losthorse
losthorse

Reputation: 1570

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea

I have been looking everywhere (google, stackoverflow, etc.) for some documentation on how to use the PostgreSQL pg_read_binary_file() function.

The only meaningful thing I can find is this page in the official documentation.

Every time I try to use this function I get an error.

For example:

    SELECT pg_read_binary_file('/some/path/and/file.gif');
    ERROR:  absolute path not allowed

or

    SELECT pg_read_binary_file('file.gif');
    ERROR:  could not stat file "file.gif": No such file or directory

Do I need to have my file in a specific directory for Postgres to have access to it? If so what directory?


If it matters, the reason I am looking at this function is because I am trying to insert a file into the database without doing crazy things.

Upvotes: 2

Views: 13002

Answers (1)

losthorse
losthorse

Reputation: 1570

As stated by @a_horse_with_no_name and @guedes the solution is to ensure that the file being uploaded is on the server in the PGDATA directory.

The postgres documentation does state the file location as a requirement.

Additionally, I made a symlink from another directory to the PGDATA directory so that I would not disturb any of the postgres data structure. This seems to be working well and I don't have to do any of the above crazy things.

Upvotes: 7

Related Questions