Skip to content

Commit

Permalink
docs: Add example on how to automatically store mimetype in files table
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangwalther committed Feb 18, 2024
1 parent 46ec264 commit d726776
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/how-tos/providing-images-for-img.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ First, in addition to the minimal example, we need to store the media types and
.. code-block:: postgres
alter table files
add column type text,
add column type text generated always as (byteamagic_mime(substr(blob, 0, 4100))) stored,
add column name text;
This uses the :code:`byteamagic_mime()` function from the `pg_byteamagic extension <https://github.com/nmandery/pg_byteamagic>`_ to automatically generate the mimetype in the :code:`files` table. To guess the type of a file, it's generally enough to look at the beginning of the file, which is more efficient.

Next, we set modify the function to set the content type and filename.
We use this opportunity to configure some basic, client-side caching.
For production, you probably want to configure additional caches, e.g. on the :ref:`reverse proxy <nginx>`.
Expand Down

0 comments on commit d726776

Please sign in to comment.