What is the best way to store videos, audios, images, documents in a bank?

1

I want to create a repository system where people can store videos, audios, pdfs, images, etc. I will probably use PGSQL and wonder what the best strategy for storing this data is that it may be different in size and type.

Thanks in advance.

    
asked by anonymous 09.03.2018 / 16:14

2 answers

1

The simplest solution is to store the file in a directory (folder) and the location (or other reference to this file) in the database. For example, let's say you go to store PDF files. You can save the documents in a directory called "PDFs" and create a table with id and location of these documents. As in id: 0001, uri: PDFs / documento_0001.pdf

You could use software such as DSpace , for example.

    
09.03.2018 / 16:26
0

You can store the contents of a file in a column of type BYTEA let's see:

CREATE TABLE tb_arquivo
(
    id BIGSERIAL PRIMARY KEY, -- Identificador unico do arquivo
    nome TEXT NOT NULL,       -- Nome/Path original do arquivo
    conteudo BYTEA NOT NULL,  -- Conteudo do arquivo
    tamanho BIGINT NOT NULL,  -- Tamanho total do arquivo
    md5 TEXT NOT NULL         -- Assinatura MD5 do arquivo
);

The content of the file can be read through the function pg_read_binary_file() and its attributes can be obtained through the function pg_stat_file() .

Assuming the file is written to the database server disk in your PG_DATA :

Writing a file to this table would look like this:

INSERT INTO
    tb_arquivo ( nome, conteudo, tamanho, md5 )
VALUES
    ( 'imagem.png',
    pg_read_binary_file('imagem.png'),
    (pg_stat_file('imagem.png')).size,
    md5(pg_read_binary_file('imagem.png')) );
    
14.03.2018 / 19:55