# PostgreSQL Blob Storage Setup This project has been updated to store uploaded files as blobs in PostgreSQL using Prisma ORM. ## Database Schema The `File` model in `prisma/schema.prisma`: - `id`: Unique identifier (CUID) - `filename`: Original filename - `mimetype`: File MIME type - `size`: File size in bytes - `data`: File content as binary data (PostgreSQL ByteA type) - `createdAt`: Timestamp when file was uploaded - `updatedAt`: Last update timestamp ## Setup Instructions ### 1. Start PostgreSQL Database ```bash # Using Docker Compose docker-compose up -d postgres # Or use your own PostgreSQL instance # Update DATABASE_URL in .env accordingly ``` ### 2. Database Migration ```bash # Run Prisma migrations npx prisma migrate dev --name init # Generate Prisma Client npx prisma generate ``` ### 3. Start Development Server ```bash npm run dev ``` ## API Endpoints ### Upload File - **POST** `/api/upload` - **Content-Type**: `multipart/form-data` - **Body**: Form data with `file` field - **Response**: File metadata (id, filename, mimetype, size, createdAt) ### List Files - **GET** `/api/files` - **Response**: Array of file metadata (excluding binary data) ### Download File - **GET** `/api/files/[id]` - **Response**: File content with appropriate headers - **Headers**: Content-Type, Content-Disposition, Content-Length ## Testing 1. Open `http://localhost:3000` to test with the main application 2. Use `test-upload.html` for simple testing 3. Use Prisma Studio for database inspection: ```bash npx prisma studio ``` ## Environment Variables - `DATABASE_URL`: PostgreSQL connection string - `ROOT_PATH`: Project root path (for legacy file system operations) ## Docker Setup The project includes Docker Compose configuration for easy PostgreSQL setup: - PostgreSQL 15 with persistent storage - Automatic database creation - Port mapping: localhost:5432