Skip to main content
GET
/
api
/
files
/
stats
Get User Stats
curl --request GET \
  --url https://api.example.com/api/files/stats
{
  "file_count": {},
  "total_storage": {},
  "file_types": [
    {
      "extension": "<string>",
      "count": {},
      "total_size": {}
    }
  ],
  "error": "<string>"
}

Authentication

This endpoint requires Bearer token authentication.
Authorization: Bearer YOUR_JWT_TOKEN

Request

No parameters required. Statistics are automatically calculated for the authenticated user.

Response

file_count
int64
Total number of files owned by the user
total_storage
int64
Total storage used in bytes (sum of all file sizes)
file_types
array
Breakdown of files by extension, sorted by total size (descending)
extension
string
File extension (lowercase, without dot). Files without extensions are labeled as "no_extension"
count
int64
Number of files with this extension
total_size
int64
Combined size of all files with this extension (in bytes)

Error Responses

error
string
Error message describing the failure

401 Unauthorized

{
  "error": "User not authenticated"
}

500 Internal Server Error

{
  "error": "Failed to get file count"
}
Other possible 500 errors:
  • "Failed to get storage usage"
  • "Failed to get file statistics"

Examples

curl -X GET https://api.defdrive.com/api/files/stats \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Success Response Example

{
  "file_count": 47,
  "total_storage": 125829120,
  "file_types": [
    {
      "extension": "zip",
      "count": 5,
      "total_size": 52428800
    },
    {
      "extension": "pdf",
      "count": 12,
      "total_size": 41943040
    },
    {
      "extension": "png",
      "count": 18,
      "total_size": 20971520
    },
    {
      "extension": "txt",
      "count": 8,
      "total_size": 8192000
    },
    {
      "extension": "jpg",
      "count": 3,
      "total_size": 2097152
    },
    {
      "extension": "no_extension",
      "count": 1,
      "total_size": 388608
    }
  ]
}
File type statistics are calculated using a PostgreSQL query that extracts file extensions from the filename. The results are sorted by total size (largest first) and exclude soft-deleted files (deleted_at IS NULL).
The total_storage value represents actual file sizes stored in the database. If physical files are deleted or modified outside the API, this value may become inaccurate.

Build docs developers (and LLMs) love