# Storage

## Upload Methods

### Method 1: Direct File Upload (Form Data)

Upload a file directly from your local system using multipart/form-data.

Request

```bash
curl --location --request PUT 'https://files.storagecdn.online/upload' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--form 'file=@"/path/to/your/file.png"'
```

Parameters

| Parameter | Type | Required | Description                                                  |
| --------- | ---- | -------- | ------------------------------------------------------------ |
| `file`    | File | Yes      | The file to upload. Use `@` prefix followed by the file path |

Example

```bash
curl --location --request PUT 'https://files.storagecdn.online/upload' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--form 'file=@"/Users/john/Documents/image.png"'
```

Use Cases

* Uploading files from local file system
* Direct file uploads from applications
* Best for: Command-line uploads, server-to-server transfers

***

### Method 2: Base64 Upload (JSON)

Upload a file as a base64-encoded string in JSON format. Base64 string can be either raw or data string

Request

```bash
curl --location --request PUT 'https://files.storagecdn.online/upload' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "base64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
}'
```

Request Body

```json
{
  "base64": "YOUR_BASE64_ENCODED_FILE_STRING"
}
```

Parameters

| Parameter | Type   | Required | Description                 |
| --------- | ------ | -------- | --------------------------- |
| `base64`  | String | Yes      | Base64-encoded file content |

Example

```bash
curl --location --request PUT 'https://files.storagecdn.online/upload' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "base64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
}'
```

Use Cases

* Uploading files from web applications
* When file is already in base64 format
* Best for: Browser-based uploads, embedded images, API integrations

Notes

* Ensure your file is properly base64-encoded before sending
* Base64 encoding increases file size by approximately 33%
* Maximum file size may be limited by your API plan

***

### Method 3: File URL Upload (JSON)

Upload a file by providing a publicly accessible URL. The server will fetch and store the file.

Request

```bash
curl --location --request PUT 'https://files.storagecdn.online/upload' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "file_url": "https://example.com/path/to/file.png"
}'
```

Request Body

```json
{
  "file_url": "https://example.com/path/to/file.png"
}
```

Parameters

| Parameter  | Type         | Required | Description                                   |
| ---------- | ------------ | -------- | --------------------------------------------- |
| `file_url` | String (URL) | Yes      | Publicly accessible URL of the file to upload |

Example

```bash
curl --location --request PUT 'https://files.storagecdn.online/upload' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "file_url": "https://file.com/images/sample.png"
}'
```

Use Cases

* Importing files from external sources
* Migrating files from other storage services
* Best for: Bulk imports, file migrations, webhook integrations

Requirements

* The URL must be publicly accessible (no authentication required)
* The file must be directly downloadable
* HTTPS URLs are recommended

***

## Response Format

### Success Response

Status Code: `200 OK`

```json
{
    "success": true,
    "file_url": "https://files.storagecdn.online/image/2b847255-e028-4cf7-a2aa-c638f3e15cbc.webp"
}
```

### Error Response

Status Code: `400 Bad Request`

```json
{
    "success": false,
    "message": "Error message here"
}
```

***
