Skip to main content

GET /api/user/limits

Retrieves the current user’s file count and storage limits along with their current usage and remaining quota. This endpoint is useful for displaying quota information to users.

Authentication

This endpoint requires authentication. Include the JWT token in the Authorization header:
Authorization: Bearer YOUR_JWT_TOKEN

Response

max_files
integer
Maximum number of files the user can upload (default: 100)
max_storage
integer
Maximum storage in bytes the user can use (default: 1073741824 = 1GB)
current_files
integer
Current number of files the user has uploaded
current_storage
integer
Current storage used in bytes
remaining_files
integer
Number of files the user can still upload (max_files - current_files)
remaining_storage
integer
Remaining storage in bytes (max_storage - current_storage)

Error responses

401 Unauthorized
object
User is not authenticated
{
  "error": "User not authenticated"
}
500 Internal Server Error
object
Failed to retrieve user information or calculate usage
{
  "error": "Failed to get user information"
}

Example request

curl -X GET http://localhost:8080/api/user/limits \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Example response

{
  "max_files": 100,
  "max_storage": 1073741824,
  "current_files": 15,
  "current_storage": 52428800,
  "remaining_files": 85,
  "remaining_storage": 1021313024
}

Use cases

Display quota to users

Show users their current usage and remaining quota in your application’s UI

Prevent upload failures

Check limits before attempting uploads to provide better user feedback

Usage analytics

Track user storage and file count patterns over time

Quota warnings

Alert users when they’re approaching their limits (e.g., 90% full)

Implementation details

This endpoint is implemented in controllers/user.go:102-137. It performs two database queries:
  1. COUNT(*) to get the number of files
  2. COALESCE(SUM(size), 0) to get total storage used
The remaining values are calculated as max - current for both files and storage.

Build docs developers (and LLMs) love