---
title: "Recreating S3 in Postgres using PostgREST"
description: "A simple S3-like file server can be built inside Postgres by storing binary data in a BYTEA table and exposing it through PostgREST's functions-as-RPC via the Neon Data API."
url: "https://swe.quest/articles/recreating-s3-in-postgres-using-postgrest-d07b4a06448dac82"
canonical: "https://neon.com/blog/recreating-s3-in-postgres-using-postgrest"
source: "Neon"
published: "2025-05-27"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["postgres","api-design","identity-auth","sql"]
---

# Recreating S3 in Postgres using PostgREST

A post on [Neon](https://swe.quest/sources/neon.md), published 2025-05-27, 7 min read, How-to. Original: [https://neon.com/blog/recreating-s3-in-postgres-using-postgrest](https://neon.com/blog/recreating-s3-in-postgres-using-postgrest)

## Summary

A simple S3-like file server can be built inside Postgres by storing binary data in a BYTEA table and exposing it through PostgREST's functions-as-RPC via the Neon Data API. A custom "\*/\*" domain lets a PL/pgSQL function return arbitrary media types and set Content-Type, Content-Disposition and Cache-Control headers, and generated columns compute size, MIME type and SHA-256 hash. Row-level security policies on anonymous and authenticated roles, with JWT-based user IDs, restrict access to public or owned blobs. Tables grant SELECT to anonymous users by default, so RLS setup is essential, and the pattern is meant as a teaching vehicle rather than a real S3 replacement.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [API design](https://swe.quest/tags/api-design.md) (Backend & APIs)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- SQL and PL/pgSQL functions ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- JWT authentication ([easy posts on Identity & auth](https://swe.quest/tags/identity-auth.md?difficulty=easy))

## Keywords

PostgREST, Neon Data API, Row-Level Security, pgcrypto, Neon Auth, S3, BYTEA

## Related posts

- [Storage is now available in Supabase](https://swe.quest/articles/storage-is-now-available-in-supabase-a17d1a6604548758.md): Supabase · 2021-03-30 · Medium · 7 min read · Storage systems, PostgreSQL, Identity & auth, System design, TypeScript
  Supabase Storage is an object store built as a custom TypeScript/Fastify API server behind Kong, with object metadata and access policies kept in each project's Postgres database and objects stored in S3.
- [Supabase Storage now in Beta](https://swe.quest/articles/supabase-storage-now-in-beta-146dd8398549e2a4.md): Supabase · 2021-07-27 · Medium · 7 min read · Storage systems, Identity & auth, PostgreSQL, JavaScript
  Supabase Storage moves to Beta with range-request streaming for audio/video, whole-bucket public visibility (private by default, to avoid S3-style per-object exposure), directory uploads via the File and Directory Entries API, an RLS policy editor with SQL templates, and a local-filesystem backend so self-hosted setups need no S3.
- [How to Set Up Row-Level Security in Postgres Using AWS Cognito](https://swe.quest/articles/how-to-set-up-row-level-security-in-postgres-using-aws-cognito-7cb6bed6c9694d22.md): Neon · 2024-12-04 · Medium · 5 min read · PostgreSQL, Identity & auth, JavaScript, Serverless
  Postgres row-level security can be driven by AWS Cognito JWTs: a Cognito User Pool issues tokens, and Neon Authorize validates them and maps claims like \`sub\` into Postgres session variables.
- [How to create an AWS S3 bucket for Postgres backups](https://swe.quest/articles/how-to-create-an-aws-s3-bucket-for-postgres-backups-1b827136764e94f1.md): Neon · 2024-10-28 · Medium · 4 min read · Cloud platforms, Identity & auth, PostgreSQL, CI/CD, Multi-tenancy
  Part 1 of a series on automating nightly Postgres backups from many Neon projects to S3 via scheduled GitHub Actions covers the AWS setup.
- [Is “SQL from the frontend” viable?](https://swe.quest/articles/is-sql-from-the-frontend-viable-7fa2effc8f7be530.md): Neon · 2024-11-07 · Easy · 3 min read · PostgreSQL, Identity & auth, System design, Security
  Letting the frontend query the database directly, via tools like PostgREST or Firebase, can sharply speed up development by removing backend abstraction layers and frontend/backend team dependencies, which makes it attractive for prototypes and many apps.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
