> ## Documentation Index
> Fetch the complete documentation index at: https://help.hubsy.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload File

> Upload a file to your Hubsy Cloud account

## Overview

Upload a new file to your Hubsy Cloud storage. Supports multipart/form-data for file uploads.

## Request Body

<ParamField body="file" type="file" required>
  The file to upload (binary data)
</ParamField>

<ParamField body="folder_id" type="string">
  ID of the folder to upload to. Omit to upload to root directory.
</ParamField>

<ParamField body="name" type="string">
  Custom filename (optional). If not provided, uses the original filename.
</ParamField>

<ParamField body="overwrite" type="boolean" default="false">
  If true and a file with the same name exists, it will be overwritten. Otherwise, a new file with a numbered suffix is created.
</ParamField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.hubsy.cloud/v1/files/upload \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "file=@/path/to/document.pdf" \
    -F "folder_id=folder_123" \
    -F "name=my-document.pdf"
  ```

  ```javascript JavaScript theme={null}
  const formData = new FormData();
  formData.append('file', fileInput.files[0]);
  formData.append('folder_id', 'folder_123');
  formData.append('name', 'my-document.pdf');

  const response = await fetch('https://api.hubsy.cloud/v1/files/upload', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    },
    body: formData
  });

  const data = await response.json();
  console.log(data.data);
  ```

  ```python Python theme={null}
  import requests

  files = {'file': open('/path/to/document.pdf', 'rb')}
  data = {
      'folder_id': 'folder_123',
      'name': 'my-document.pdf'
  }

  response = requests.post(
      'https://api.hubsy.cloud/v1/files/upload',
      files=files,
      data=data,
      headers={'Authorization': 'Bearer YOUR_API_KEY'}
  )

  file_info = response.json()['data']
  ```

  ```php PHP theme={null}
  $ch = curl_init();

  $file = new CURLFile('/path/to/document.pdf');
  $data = [
      'file' => $file,
      'folder_id' => 'folder_123',
      'name' => 'my-document.pdf'
  ];

  curl_setopt($ch, CURLOPT_URL, 'https://api.hubsy.cloud/v1/files/upload');
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Authorization: Bearer YOUR_API_KEY'
  ]);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  $data = json_decode($response, true);
  ```
</CodeGroup>

## Response

<ResponseField name="success" type="boolean">
  Indicates if the upload was successful
</ResponseField>

<ResponseField name="data" type="object">
  Uploaded file information

  <Expandable title="File Object">
    <ResponseField name="id" type="string">
      Unique file identifier
    </ResponseField>

    <ResponseField name="name" type="string">
      File name with extension
    </ResponseField>

    <ResponseField name="size" type="integer">
      File size in bytes
    </ResponseField>

    <ResponseField name="type" type="string">
      MIME type (e.g., "application/pdf")
    </ResponseField>

    <ResponseField name="category" type="string">
      File category: `image`, `video`, `audio`, `document`, `archive`, `other`
    </ResponseField>

    <ResponseField name="folder_id" type="string">
      ID of parent folder, or `null` if in root
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO 8601 timestamp of upload
    </ResponseField>

    <ResponseField name="modified_at" type="string">
      ISO 8601 timestamp (same as created\_at for new uploads)
    </ResponseField>

    <ResponseField name="thumbnail_url" type="string">
      URL to file thumbnail (if available)
    </ResponseField>

    <ResponseField name="download_url" type="string">
      Direct download URL (expires in 1 hour)
    </ResponseField>

    <ResponseField name="md5_hash" type="string">
      MD5 hash of file contents
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Response

```json theme={null}
{
  "success": true,
  "data": {
    "id": "file_xyz789",
    "name": "my-document.pdf",
    "size": 2458624,
    "type": "application/pdf",
    "category": "document",
    "folder_id": "folder_123",
    "created_at": "2024-01-15T14:30:00Z",
    "modified_at": "2024-01-15T14:30:00Z",
    "thumbnail_url": "https://cdn.hubsy.cloud/thumbs/file_xyz789.jpg",
    "download_url": "https://cdn.hubsy.cloud/download/file_xyz789?token=abc123",
    "md5_hash": "5d41402abc4b2a76b9719d911017c592"
  }
}
```

## Error Responses

<ResponseExample>
  ```json File Too Large theme={null}
  {
    "success": false,
    "error": {
      "code": "file_too_large",
      "message": "File exceeds maximum size limit for your plan",
      "details": {
        "file_size": 6000000000,
        "max_size": 5000000000,
        "plan": "pro"
      }
    }
  }
  ```

  ```json Storage Exceeded theme={null}
  {
    "success": false,
    "error": {
      "code": "storage_exceeded",
      "message": "Storage quota exceeded",
      "details": {
        "current_usage": 1073741824,
        "storage_limit": 1073741824,
        "required_space": 2458624
      }
    }
  }
  ```

  ```json Invalid Folder theme={null}
  {
    "success": false,
    "error": {
      "code": "not_found",
      "message": "Folder not found"
    }
  }
  ```

  ```json Missing File theme={null}
  {
    "success": false,
    "error": {
      "code": "invalid_request",
      "message": "No file provided in request"
    }
  }
  ```
</ResponseExample>

## File Size Limits

Maximum file size varies by plan:

| Plan       | Max File Size |
| ---------- | ------------- |
| Free       | 100 MB        |
| Pro        | 5 GB          |
| Enterprise | 10 GB         |

## Upload Best Practices

<AccordionGroup>
  <Accordion title="Large File Uploads" icon="file-arrow-up">
    For files larger than 100 MB:

    * Use chunked upload (coming soon)
    * Implement retry logic
    * Show progress to users
    * Handle network interruptions
  </Accordion>

  <Accordion title="Verify Uploads" icon="check">
    Verify upload success:

    * Check response status code (200)
    * Verify `success: true` in response
    * Compare MD5 hash if critical
    * Store file ID for future reference
  </Accordion>

  <Accordion title="Error Handling" icon="triangle-exclamation">
    Handle common errors:

    * Storage exceeded → Notify user to upgrade
    * File too large → Compress or split file
    * Invalid folder → Verify folder exists
    * Rate limit → Implement exponential backoff
  </Accordion>
</AccordionGroup>

## Notes

* Supported file types: All types accepted
* Files are scanned for viruses automatically
* Duplicate filenames are handled based on `overwrite` parameter
* Upload progress tracking available via chunked upload API (coming soon)
* MD5 hash can be used to verify file integrity
