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

# Uploads Guide

> How to upload files to Drime Cloud

## Choosing the Right Method

Drime Cloud offers several upload methods depending on your file size:

<CardGroup cols={2}>
  <Card title="Direct Upload" icon="upload" href="/api-reference/uploads/upload-file">
    **\< 5 MB** - Simple and fast via multipart/form-data
  </Card>

  <Card title="Presigned URL" icon="link" href="/api-reference/uploads/presign-url">
    **\< 5 MB** - Direct upload to S3 with presigned URL
  </Card>

  <Card title="Multipart Upload" icon="layer-group" href="/api-reference/multipart/create-multipart">
    **≥ 5 MB** - For large files, upload in chunks
  </Card>
</CardGroup>

## Simple Upload (\< 5 MB)

For small files, use direct upload:

```javascript theme={null}
const formData = new FormData();
formData.append('file', file);
formData.append('workspaceId', '0');

const response = await fetch('https://app.drime.cloud/api/v1/uploads', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer TOKEN' },
  body: formData
});
```

## Presigned URL Upload (\< 5 MB)

More performant, as it uploads directly to storage:

<Steps>
  <Step title="Get the presigned URL">
    ```javascript theme={null}
    const { url, key } = await fetch('/s3/simple/presign', {
      method: 'POST',
      body: JSON.stringify({ filename, mime, size, extension })
    }).then(r => r.json());
    ```
  </Step>

  <Step title="Upload to S3">
    ```javascript theme={null}
    await fetch(url, { method: 'PUT', body: file });
    ```
  </Step>

  <Step title="Register the file">
    ```javascript theme={null}
    await fetch('/s3/entries', {
      method: 'POST',
      body: JSON.stringify({ filename: key.split('/').pop(), size, clientName })
    });
    ```
  </Step>
</Steps>

## Multipart Upload (≥ 5 MB)

For large files, split into 5 MB chunks:

<Steps>
  <Step title="Initialize">
    Call `/s3/multipart/create` to get an `uploadId`
  </Step>

  <Step title="Sign URLs">
    Call `/s3/multipart/batch-sign-part-urls` for each part
  </Step>

  <Step title="Upload parts">
    PUT each chunk to its URL, collect the ETags
  </Step>

  <Step title="Complete">
    Call `/s3/multipart/complete` with all ETags
  </Step>

  <Step title="Register">
    Call `/s3/entries` to create the file entry
  </Step>
</Steps>

<Tip>
  If interrupted, use `/s3/multipart/get-uploaded-parts` to resume the upload where it left off.
</Tip>

## Duplicate Validation

Before uploading, check if the file already exists:

```javascript theme={null}
const { duplicates } = await fetch('/uploads/validate', {
  method: 'POST',
  body: JSON.stringify({
    files: [{ name: 'photo.jpg', size: 1024, relativePath: '/photos' }]
  })
}).then(r => r.json());

if (duplicates.length > 0) {
  // Ask the user or auto-rename
  const { name } = await fetch('/entry/getAvailableName', {
    method: 'POST',
    body: JSON.stringify({ name: 'photo.jpg', parentId: null })
  }).then(r => r.json());
}
```
