Skip to main content

Local File Upload API Reference

This document provides detailed information about the Local File Upload API endpoint. This endpoint is available only in local development environments.

Overview​

The Local File Upload API endpoint allows developers to upload files to the local filesystem during development and testing. This endpoint is explicitly restricted to local environments and should not be used in production.

Authentication​

This endpoint does not require authentication as it's intended for local development use only.

Endpoints​

Upload File Locally​

Uploads a file to the local filesystem in a structured directory format.

POST /local-upload/:cat/:seg/:fileName

URL Parameters​

  • cat: Category name (used as a directory)
  • seg: Segment name (used as a subdirectory)
  • fileName: Name of the file to be saved

Request Body​

This endpoint uses multipart/form-data format:

file: [Binary File Data]

Response​

{
"status": "success"
}

Error Responses​

  • 400 Bad Request: When accessing the endpoint in a non-local environment

    {
    "statusCode": 400,
    "message": "This endpoint is only available in local environment",
    "error": "Bad Request"
    }
  • 400 Bad Request: When the file upload process fails

    {
    "statusCode": 400,
    "message": "Failed to upload file",
    "error": "Bad Request"
    }

Usage Examples​

cURL Example​

curl -X POST \
'http://localhost:3000/local-upload/images/profile/avatar.jpg' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@/path/to/local/image.jpg'

JavaScript Example​

const formData = new FormData();
formData.append('file', fileInput.files[0]);

fetch('http://localhost:3000/local-upload/images/profile/avatar.jpg', {
method: 'POST',
body: formData,
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error('Error:', error));

Important Notes​

  1. This API endpoint is only available in local development environments.
  2. Files are stored in the application's directory structure, making them easily accessible for testing.
  3. The directory structure is automatically created if it doesn't exist.