Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.moodmnky.com/llms.txt

Use this file to discover all available pages before exploring further.

Storage Services

Storage Services

Overview

MOOD MNKY’s storage services provide secure and scalable solutions for managing various types of data, from user-generated content to application assets. Our primary storage is powered by Supabase Storage with both standard API access and S3-compatible protocol support.

Storage Solutions

Database Storage

Structured data storage with Supabase/PostgreSQL

Object Storage

Unstructured file and media storage via Supabase Storage

S3-Compatible Storage

Direct S3 protocol access to Supabase Storage

Local Storage

Client-side persistent storage options

Supabase Storage

Supabase Storage provides a secure, scalable solution for storing and serving files in the MOOD MNKY ecosystem. It’s integrated with Supabase’s Row Level Security (RLS) for fine-grained access control.

Standard API Access

The standard way to interact with Supabase Storage is through the Supabase client:
import { supabase } from '@repo/supabase-client';

// Upload a file
const { data, error } = await supabase
  .storage
  .from('bucket-name')
  .upload('path/to/file.jpg', file);

// Download a file
const { data, error } = await supabase
  .storage
  .from('bucket-name')
  .download('path/to/file.jpg');

// Get a public URL
const { data } = supabase
  .storage
  .from('bucket-name')
  .getPublicUrl('path/to/file.jpg');

S3-Compatible API Access

For advanced use cases, Supabase Storage also supports the S3 protocol, allowing you to use AWS SDK or other S3-compatible tools:
import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';

// Initialize S3 client with Supabase credentials
const s3Client = new S3Client({
  endpoint: process.env.SUPABASE_S3_URL,
  region: process.env.SUPABASE_S3_REGION,
  credentials: {
    accessKeyId: process.env.SUPABASE_S3_ACCESS_KEY_ID,
    secretAccessKey: process.env.SUPABASE_S3_SECRET_ACCESS_KEY,
  },
  forcePathStyle: true, // Required for Supabase Storage
});

// Upload a file
const putCommand = new PutObjectCommand({
  Bucket: 'bucket-name',
  Key: 'path/to/file.jpg',
  Body: fileBuffer,
  ContentType: 'image/jpeg',
});
await s3Client.send(putCommand);

// Download a file
const getCommand = new GetObjectCommand({
  Bucket: 'bucket-name',
  Key: 'path/to/file.jpg',
});
const response = await s3Client.send(getCommand);
const fileContent = await response.Body.transformToByteArray();

Environment Configuration

The storage service is configured through environment variables:
# Standard Supabase Storage (via Supabase client)
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key

# S3-Compatible Access
SUPABASE_S3_URL=https://your-project.supabase.co/storage/v1/s3
SUPABASE_S3_REGION=your-region
SUPABASE_S3_ACCESS_KEY_ID=your-access-key-id
SUPABASE_S3_SECRET_ACCESS_KEY=your-secret-access-key
These variables are already configured in the production environment.

Storage Buckets

The MOOD MNKY platform uses several storage buckets for different purposes:
Bucket NamePurposeAccess Control
publicPublicly accessible assetsPublic read
profilesUser profile pictures and dataUser-specific access
productsProduct images and assetsPublic read
user-contentUser-generated contentCreator and admin access
tempTemporary storage for processingTime-limited access

Security Best Practices

  1. Use RLS Policies: Always define Row Level Security policies for your storage buckets
  2. Validate File Types: Implement client and server-side validation for uploaded files
  3. Set Size Limits: Configure maximum file sizes to prevent abuse
  4. Use Signed URLs: For temporary access to restricted files
  5. Implement Content Scanning: For user-uploaded content

Performance Optimization

  1. Image Transformations: Use Supabase Storage image transformations for responsive images
  2. CDN Integration: Configure a CDN in front of Supabase Storage for improved delivery
  3. Chunked Uploads: Implement chunked uploads for large files
  4. Optimized File Formats: Convert images to WebP and other optimized formats
  5. Lazy Loading: Implement lazy loading for images and other media