File Uploader API

Secure, fast, and simple file storage for MyResto Today

🚀 Overview

This API allows you to upload various file types (images, documents, videos) and retrieve them via a permanent URL. Metadata is stored in a PostgreSQL database.

Base URL: https://files.myrestotoday.io

💾 Database Storage

When a file is uploaded, it is saved to the uploads/ directory with a unique hashed name. Its metadata is stored in the file_uploads table:

Column Type Description
id SERIAL (PK) Unique file ID (used for retrieval).
stored_name VARCHAR Unique filename on disk (e.g., 1706..._abc.jpg).
original_name VARCHAR The original name of the uploaded file.
mime_type VARCHAR MIME type (e.g., image/png, application/pdf).
file_size BIGINT File size in bytes.
created_at TIMESTAMP Upload timestamp.

👁️ How Files are Displayed

Files are not accessed directly to ensure security and metadata integrity. Instead, they are served via read.php:

  1. Request: You request read.php?id=123.
  2. Lookup: The API finds the record for ID 123 in the database.
  3. Headers: It sends the correct Content-Type header (e.g., image/jpeg) based on the database record.
  4. Output: The raw file content is streamed to the browser.

This allows images to display inline in <img> tags and PDFs to open in the browser.

📤 Upload File

POST /upload.php

Parameters

Field Type Required Description
file File Yes The file object to upload (multipart/form-data).

Response Example

{
    "status": "success",
    "message": "File uploaded successfully",
    "data": {
        "id": 123,
        "filename": "1706691234_abc123.jpg",
        "original_name": "my-photo.jpg",
        "url": "https://files.myrestotoday.io/read.php?id=123",
        "direct_url": "https://files.myrestotoday.io/read.php?file=1706691234_abc123.jpg"
    }
}

📖 Read File

GET /read.php

Parameters

Query Param Example Description
id ?id=123 Retrieve file by its Database ID (Recommended).
file ?file=name.jpg Retrieve by stored filename.