# Start a big upload

`POST https://api.mailmasker.org/api/v1/drive/uploads`

Open an upload session, to send a big file in pieces you can resume.

- Who can use it: Any signed-in account
- Area: Drive
- Answers 201 Created when it works
- Page: https://developer.mailmasker.org/drive-upload-start

Open a session here, then send the file in order, one piece at a time, with Send a piece of a big upload. If the connection drops, Check a big upload tells you where to carry on. `chunk_size` is a suggested piece size; any size works. The file appears in Drive when its last byte arrives. homelab-cli uploads this way for files over 8 MiB.

## Parameters

| Name | In | Required | What it is | Example |
|---|---|---|---|---|
| `filename` | body | yes | The file's name in Drive. Only the last part of a path is kept. | `backup.iso` |
| `total_size` | body | yes | The file's exact size, in bytes. | `4294967296` |
| `folder_id` | body | no | The folder to put it in. Leave it out for the top level. |  |

## Good to know

- An empty file (total_size 0) is finished at once, and the answer has done set to true and its file_id.
- A file over 50 GiB, or one that won't fit in your storage limit, is refused with 413.
- You can have up to 100 uploads open at once; one more answers 429. An upload left untouched for 24 hours is thrown away.

## Examples

cURL:

```bash
curl -s -X POST 'https://api.mailmasker.org/api/v1/drive/uploads' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"filename":"backup.iso","total_size":4294967296}'
```

Perl:

```perl
use Mojo::Base -strict;
use Mojo::UserAgent;

my $ua  = Mojo::UserAgent->new;
my $res = $ua->post('https://api.mailmasker.org/api/v1/drive/uploads',
    { Authorization => "Bearer $ENV{TOKEN}" },
    json => { filename => 'backup.iso', total_size => 4294967296 })->result;
die $res->code, ' ', ($res->json('/error') // $res->message), "\n" unless $res->is_success;
print $res->body, "\n";
```

homelab-cli:

```bash
homelab-cli drive upload ./backup.iso
```

## Response

201 Created:

```json
{
  "upload_id": "0b6f3c1e-8d2a-4f7b-9e5c-3a1d2b4c6e8f",
  "offset": 0,
  "chunk_size": 8388608
}
```
